Salesforce Interview Questions – Part 3

Author posted by Jitendra on Posted on under category Categories Salesforce and tagged as Tags , , with 29 Comments on Salesforce Interview Questions – Part 3

Most Frequently Asked interview questions of Apex, Visual force, SOQL in Salesforce.com SFDC

20. In Which sequence Trigger and automation rules run in Salesforce.com

Ans : The following is the order Salesforce logic is applied to a record.

  1. Old record loaded from database (or initialized for new inserts)
  2. New record values overwrite old values
  3. System Validation Rules
  4. All Apex “before” triggers
  5. Custom Validation Rules
  6. Record saved to database (but not committed)
  7. Record reloaded from database
  8. All Apex “after” triggers
  9. Assignment rules
  10. Auto-response rules
  11. Workflow rules
  12. Escalation rules
  13. Parent Rollup Summary Formula value updated (if present)
  14. Database commit
  15. Post-commit logic (sending email)

Additional notes: There is no way to control the order of execution within each group above.


21. If one object in Salesforce have 2 triggers which runs “before insert”. Is there any way to control the sequence of execution of these triggers?

Ans : Salesforce.com has documented that trigger sequence cannot be predefined. As a best practice create one trigger per object and use comment blocks to separate different logic blocks. By having all logic in one trigger you may also be able to optimize on your SOQL queries.


22. How to delete the User from Salesforce?

Ans : As per now, salesforce does not allow to delete any user, however you can deactivate the user.

Read further…


23. How to delete the users data from Salesforce?

Ans : To delete the Users Data go to Setup | Administration Setup | Data Management |  Mass Delete Record, from there select the objects like Account, Lead etc and in criteria select the users name and delete all records of that user related to particular object.


24. How to restrict the user to see any record, lets say opportunity?

Ans : set up opportunity sharing to be private.  If both users are admins or have view all records on opportunity, then that overrides private sharing.


25. What is the difference between trigger.new and trigger.old in Apex – SFDC?

Ans :

Trigger.new :

Returns a list of the new versions of the sObject records.

Note that this sObject list is only available in insert and update triggers, and the records can only be modified in before triggers.

Trigger.old :

Returns a list of the old versions of the sObject records.

Note that this sObject list is only available in update and delete triggers.


26. How to restrict any Trigger to fire only once OR how we can avoid repeated or multiple execution of Trigger?

Ans:

Triggers can fire twice, once before workflows and once after workflows, this is documented at

http://www.salesforce.com/us/developer/docs/apexcode/ Content/ apex_triggers_order_of_execution.htm:

“The before and after triggers fire one more time only if something needs to be updated. If the fields have already been set to a value, the triggers are not fired again.”

Workaround:

Add a static boolean variable to a class, and check its value within the affected triggers.

public class HelperClass {
   public static boolean firstRun = true;
}
trigger affectedTrigger on Account (before delete, after delete, after undelete) {
    if(Trigger.isBefore){
        if(Trigger.isDelete){
            if(HelperClass.firstRun){
                Trigger.old[0].addError('Before Account Delete Error');
                HelperClass.firstRun=false;
            }
        }
    }
}

27.  What is difference between WhoId and WhatId in the Data Model of Task ?

Ans :

WhoID refers to people things. So that would be typically a Lead ID or a Contact ID
WhatID refers to object type things. That would typically be an Account ID or an Opportunity ID

Check Data Model of task here


28. Where is the option of the report for the “Custom Object with related object” and what are the condition to generate related reports?
Ans :

If the parent object is the standard object provided by the salesforce like “Account”, “Contact” then the report will be in there section with related custom object.
If both objects are the custom then the report will be in “Other Reports” Sections.

Following are the conditions to get the report of related objects:

  • On both the objects, Reports option must be enable.
  • Both object must be related either using Lookup or Master Detail type of field.

Read this article, to get detailed idea on this topic.


29. How you can provide the User Login (Authentication) in Public sites created by Salesforce.

Answer : We can provide the authentication on public sites using “Customer Portal”.