Salesforce interview questions – Part 19

181. Lets consider your custom Object named “Training__c” has field “Trainer__c”. You have set some default value in that field. Will that default value apply to new record created by apex code ?
How to make sure that record created from apex code should respect default value of fields ?
Default value in field from Apex code.
Ans :

After API 20, it should automatically populate However there is known issue for same here, click here if it impacts you.
Workaround :
If Default value of field is not getting populated by Apex then we have to use “Dynamic Apex”.  Create instance of object from sObjectType like shown below:

Training__c tr= (Training__c) Training__c.sObjectType.newSObject(null, true);

//Check if Value in field "Trainer__c" is default value
System.assertEquals('Jitendra', tr.Trainer__c);

182. What is best practice to refer dynamic custom messages in Visualforce with multi-language support ?
Ans :
Using Custom Label or OutputField or InputField tag, Platform itself will take care of internationalization. However in some cases, Message needs to be dynamic at the same time it should also support muti-language. In Custom Label, we cannot save dynamic String.

Let’s assume we want to show message something like “DEVELOPERNAME is not authorized to access this page”.
Here, Developername should be dynamically changed in visualforce which supports multilanguage. For each developername, it is not feasible to create custom labels. So below workaround can be used :

Step 1 : Create a Custom Label with text “{0} is not authorized to access this page“. In every language, dynamic value should represented by {0}.

Step 2 : In Controller of Visualforce write something like this :

String developerName = 'Some DeveloperName';
String message = String.format(Label.DEVELOPERNA, new String[] { developerName });

183. How can you update Salesforce record using Apex, when you don’t know Object API name, but you know record Id ?
Ans :
Using Dynamic Apex we can achieve this :

//Lets assume this is record Id
Id recId = 'a0P9000000ESXcV';

Schema.SObjectType token = recId.getSObjectType();
Sobject s = token.newSobject();
s.put('Id',recId );
s.put('Name', 'om');
update s;

184. How to disable Header ribbon in Salesforce Organization where Community is enabled ?
Ans : In Profile “View Global Header” controlls visibility of B lack ribbon whioch is used to switch between community.

185. How many record can be displayed in repeater or PageBlockTable in Visualforce ?
Ans : current limit is 1000 records.

186. How to display more than 1000 records in repeater or PageBlockTable component of Visualforce ?
Ans : If circumstances permits, we can use readOnly attribute available at apex page level. Read more about making complete page readonly.

187. How we can check API limits already used in any organization by using REST or SOAP API ?
Ans :
SOAP API and REST API always returns header after making successful call to Salesforce.

Sample Responses:


            <type>API REQUESTS</type>


Sforce-Limit-Info: api-usage=45/5000

188. Lets say you have written trigger on Opportynity and want to access field of Account. Can you use this Syntax – oppObj.Account.someField__c ?
Ans :
There is common missunderstanding that what is allowed in Trigger Context. Above Syntax will work on any other places like Visualforce Controller. However in Trigger, Lookup field or related list is not available implicitly, we need to query it.

189. How we can control Chatter email settings while creating or updating users using Data Loader?
Ans :
Using a dataloader update the user object’s field “DefaultGroupNotificationFrequency” with the options:

  • Email on each post
  • Daily digests
  • Weekly digests
  • Never

190. Once email is sent via Workflow, can it be tracked in Activity history related list ?
Ans :
No. If you think this is nice to have and usefull for Auditing purpose, please vote up and comment on this idea.





Related Posts


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Jitendra Zaa

Subscribe now to keep reading and get access to the full archive.

Continue Reading