Tuesday, August 1, 2017

salesforce interview questions and answers Part-3

What causes Concurrent Apex limit error in Salesforce ?

Ans : If Synchronous Apex runs more than 5 sec it considered as long running job. And we have limit that only 10 long running job can execute at a time. So, whenever 11th Synchronous apex tries to execute, it gets Concurrent Apex limit error.

What is custom metadata type ? 

Ans :
 Custom metadata was introduced generally in Summer 15 release. Before Custom metadata type, we were using Custom settings of List type. Problem with custom setting was that, during migration or in packages, data were not migrated. We had to either use data loader or some API to create initial data. However, if we package custom metadata type or migrate it, data will also be migrated along with it.


Which component in Salesforce ends with “__mdt” and “__s”?
Ans : Custom metadata types ends with “__mdt” (meta data type), just like custom object or custom fields ends with “__c”.
When we create Geolocation field in Salesforce, lets say by name “location__c” then internally Salesforce creates subfields with extension “__s“. In this case “location_latitude__s” and “location_longitude__s”.
Difference between Chatter API and Connect API.
Ans :
Chatter API is REST API for Chatter to display Salesforce data, especially in mobile applications. Responses are localized, structured for presentation, and can be filtered to contain only what the app needs
Connect API provides apex classes for accessing the same data available in Chatter REST API. Use Chatter in Apex to create custom Chatter experiences in Salesforce.
Which custom fields or relationships in salesforce ends with “__pc” and “__pr” ?
Ans : In normal scenario all custom fields ends with “__c” and relationships ends with “__r” However for Person accounts, custom fields ends with “__pc” and custom relationship ends with “__pr”.
How to report on User License field?
Ans :    Create formula field in User Object with formula “Profile.UserLicense.Name”.
Note: You need to copy and paste this value because it doesn’t show up in the fields drop down.
While creating JavaScript button to execute anonymous apex, what should you keep in mind ?
Ans : End user must needs to have “Apex Author” permission and this is something should not be granted to end user. Also, while creating JavaScript button, user must be aware that its only supported in Salesforce classic and not in Salesforce Lightning.
How to add the Document Header in Visualforce page?
Ans : Directly there is no way to add the document type in visualforce. However in most of the cases IE9 does not work with Visualforce pleasantly. And then we need to add the Document type in header. So following workaround will work.
1<apex:outputText
2escape="false"
3value="{!'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'}"/>
4<html>
5    <head>
6        <title>test</title>
7    </head>
8    <body>test</body>
9</html>
10</apex:page>

Onchange event does not work with <apex:actionsupport> in IE9. How to resolve this error?
Ans: If we hide the Header on Visualforce page then it creates lots of problem in IE9. I think there are few java-script library loaded by Header of Salesforce which makes IE9 compatible. So the best solution is to enable the Headre by using “showHeader=true” in Apex page.
If IE9 is not working with your custom visualforce page then how to tell your visualforce code to run in IE8 compatibility mode?
Ans:
Add following metatag to pages:
1<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />

It may happen that above tips will not work as lots of time the page header already sent. then how to achieve same result using Apex?
Ans:
Add below line of code in Apex (Constructor)
1Apexpages.currentPage().getHeaders().put('X-UA-Compatible''IE=8');

Read more:  https://developer.salesforce.com/blogs/developer-relations/2011/03/visualforce-rerender-and-internet-explorer-9.html

You want to display the Encrypted field on Visualforce and you are using component apex:outputText. Will it work for Encrypted fields?

Ans : Encrypted custom fields that are embedded in the <apex:outputText> component display in clear text. The <apex:outputText> component doesn’t respect the View Encrypted Data permission for users. To prevent showing sensitive information to unauthorized users, use the <apex:outputField> tag instead.

Will below query work? Explain.
1SELECT COUNT(Id), Name, Address__c FROM Opportunity GROUP BY Name
Ans :
Above query will throw an error.
Explanation : In Group by clause the columns selected must be either used in Group by clause or in aggregate functions. The Name field is neither used in aggregate methods and in group by clause and hence will result in error “Malformed Query”
 Explain difference in COUNT() and COUNT(fieldname) in SOQL.
Ans :
COUNT()
COUNT() must be the only element in the SELECT list.
You can use COUNT() with a LIMIT clause.
You can’t use COUNT() with an ORDER BY clause. Use COUNT(fieldName) instead.
You can’t use COUNT() with a GROUP BY clause for API version 19.0 and later. Use COUNT(fieldName) instead.
COUNT(fieldName):
You can use COUNT(fieldName) with an ORDER BY clause.
You can use COUNT(fieldName) with a GROUP BY clause for API version 19.0 and later.

How to write the “Where” clause in SOQL when GroupBy is used for aggregate functions?
Ans : We cannot use the “Where” clause with GroupBy for aggregate functions like SUM() instead we will need to use the “Having Clause“.
Example : Get all the opportunity where more than one record exists with same name and name contains “ABC”.
1SELECT COUNT(Id) , Name FROM Opportunity GROUP BY Name  Having COUNT(Id) > 1 AND Name like '%ABC%'
Lets consider that the first component in VF page is the Datepicker. In that case whenever the page loads, salesforce auto focus the first component resulting in Datepicker onfocus event. Because of this the Datepicker component opens automatically. How we can avoid this?
Ans :
On load event, write the javascript code to autofocus any other field or any other non-visible component.
Example :
1<span id="focusDistraction"></span>
2<script type="text/javascript">
3    /* prevent autopup of the date inputfield by the default focus behavoir */
4    window.onload=function() {
5    document.getElementById('focusDistraction').focus();
6    }
7</script>

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.