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.

Example:

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

102. How to implement the pagination in SOQL ?

Ans:
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

Example:

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.

Example:

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’”

Resolution:
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?
Ans:

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?
Ans:

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.

{!myContact['Account'][fieldname]}

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="{!acc.name}"/>
   <apex:column value="{!acc.BillingStreet}"/>
   <apex:column value="{!acc.BillingCity}"/>
   <apex:column value="{!acc.BillingPostalCode}"/>
</apex:pageBlockTable>

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


106. How to convert lead using Apex?
Ans:

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

Database.LeadConvert lc = new database.LeadConvert();
lc.setLeadId(myLead.id);

LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
lc.setConvertedStatus(convertStatus.MasterLabel);

Database.LeadConvertResult lcr = Database.convertLead(lc);
System.assert(lcr.isSuccess());

 

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

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 salesforce.com 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.

Posted

in

by


Related Posts

Comments

4 responses to “Salesforce Interview Questions – Part 11”

  1. hari Avatar
    hari

    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.
    Thanks
    Hari

  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 tlaxman0@gmaik.com

  3. Sumit Avatar
    Sumit

    I found a website with link For complete training videos on Dev 401 and Dev 501. Hope it Helps and its Free.Please check.
    http://greensfdc.blogspot.in/p/online-courses_6179.html

  4. Praveen Krishna Avatar
    Praveen Krishna

    Jitendra,

    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