Salesforce Interview Questions – Part 11

101. How to force lead assignment rule via Apex while updating or adding the Lead?
Ans : To enforce Assignment Rules in Apex you will need to perform following steps:

  1. Instantiate the “Database.DMLOptions” class.
  2. Set the “useDefaultRule” property of “assignmentRuleHeader” to True.
  3. Finally call a native method on your Lead called “setOptions”, with the Database.DMLOptions instance as the argument.


// to turn ON the Assignment Rules in Apex
Database.DMLOptions dmlOptn = new Database.DMLOptions();
dmlOptn.assignmentRuleHeader.useDefaultRule = true;

102. How to implement the pagination in SOQL ?

In spring 12, Salesforce has come up with ability of SOQL to get records from position “X” instead of position “1” every time to help creating pagination feature.

Pagination in SOQL using keyword Offset
Pagination in SOQL using keyword Offset


Select Id, Name from Lead LIMIT 5 OFFSET 2

Above query will return 5 Lead records starting from record number 10 (5×2).

Read more here about SOQL pagination

103. Access custom controller-defined enum in custom component ?
Ans :

We cannot reference the enum directly since the enum itself is not visible to the page and you can’t make it a property.


Apex class:

global with sharing class My_Controller {
  public Case currCase {get; set; }
  public enum StatusValue {RED, YELLOW, GREEN}

  public StatusValues getColorStatus() {
    return StatusValue.RED;  //demo code - just return red

Visualforce page:

<apex:image url='stopsign.png' rendered="{!colorStatus == StatusValue.RED}" />

Above code snippet will throw error something like “Save Error: Unknown property ‘My_Controller.statusValue’”

Add below method in Apex Controller:

public String currentStatusValue { get{ return getColorStatus().name(); }}

and change Visualforce code to

<apex:image url='stopsign.png' rendered="{!currentStatusValue == 'RED'}" />

The same question was raised in this thread of stackExchange

104. How to generate the random string or random password using Apex?

Integer len = 10;
Blob blobKey = crypto.generateAesKey(128);
String key = EncodingUtil.convertToHex(blobKey);
String pwd = key.substring(0,len);

105. What is dynamic binding in salesforce?

Dynamic Visualforce bindings are a way of writing generic Visualforce pages that display information about records without necessarily knowing which fields to show. In other words, fields on the page are determined at run time, rather than compile time. This allows a developer to design a single page that renders differently for various audiences, based on their permissions or preferences. Dynamic bindings are useful for Visualforce pages included in managed packages since they allow for the presentation of data specific to each subscriber with very little coding.

Example 1:
Access the Account name from Contact.


Example 2:

Consider Data type in Apex

public Map<String, List<Account>> accountsMap {get; set;}

Visualforce page:

<apex:variable value="A" var="selectedKey" />
<apex:pageBlockTable value="{!accountsMap[selectedKey]}" var="acc">
   <apex:column value="{!}"/>
   <apex:column value="{!acc.BillingStreet}"/>
   <apex:column value="{!acc.BillingCity}"/>
   <apex:column value="{!acc.BillingPostalCode}"/>

Read more about Visualforce dynamic binding on bob buzzard’s blog

106. How to convert lead using Apex?

Lead myLead = new Lead(LastName = 'Foo', Company='Foo Bar');
insert myLead;

Database.LeadConvert lc = new database.LeadConvert();

LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];

Database.LeadConvertResult lcr = Database.convertLead(lc);


108. How can you determine that email is actually sent or not from the salesforce?

There is an Email log that you could use. It’s available in the setup menu under Monitoring.

It’s only for the past 30 days and you would have to manually check it.

From the email log page: “Email logs describe all emails sent through and can be used to help identify the status of an email delivery. Email logs are CSV files that provide information such as the email address of each email sender and its recipient, the date and time each email was sent, and any error code associated with each email. Logs are only available for the past 30 days.”

109. In salesforce which fields are indexed automatically?
Ans :

The following fields are indexed by default:

  • primary keys (Id, Name and Owner fields),
  • foreign keys (lookup or master-detail relationship fields),
  • audit dates (such as LastModifiedDate),
  • Custom fields marked as External ID or Unique.

Read more on indexing from Salesforce Documentation

110 : Give any scenario when you cannot change the currency field type to numeric type.
Ans :
When the field is used either in Apex class or trigger.




Related Posts


4 responses to “Salesforce Interview Questions – Part 11”

  1. hari Avatar

    we have picklist with values 1,2,3,4….52 weeks. and two fields called start_date__c, and End_date__c. if i select picklist val week-1 , in start_Date__c field it has to show first day (date) of that week in the month of January, and in
    End_date__c field it has to show last day (date) of that week .how can we code this.

  2. Thadaka Laxman Avatar
    Thadaka Laxman

    hi sir how to create an a project an salesforce or sales force project developing flow plz replay me to this mail

  3. Sumit Avatar

    I found a website with link For complete training videos on Dev 401 and Dev 501. Hope it Helps and its Free.Please check.

  4. Praveen Krishna Avatar
    Praveen Krishna


    OFFSET query example will result 3-7 I believe. Please correct me if I am wrong.
    great blog bro… Learnt a lot from your blog. thanks a lot for sharing your knowledge.

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