Salesforce has a bunch of rules that can be defined on objects and fields. For example you can define validation rules, workflow rules, assignment rules, escalation rules, auto-response rules, triggers etc.

As an administrator and developer it is important for you to understand the order in which these rules and triggers are executed. Here is the gist of sequence in which Salesforce will evaluate different rules (For detailed explanation, please click here).

(By the way if you are preparing for Advanced Developer Certification i.e. DEV-501, there are a couple of questions on the order of execution)

  1. System Validation rule (required field, field format) (SV)
  2. Before Triggers are executed (BT)
  3. Custom Validation rules are checked (CV)
  4. After Triggers are executed (AT)
  5. Assignment Rules are executed (AR)
  6. Auto-Response Rules are executed (ARR)
  7. Workflow Rules are executed (WR)
    1. Before and after triggers are executed one more time if the workflow rule updates a field (BT & AT)
  8. Escalation Rules are executed (ER)
  9. Parent Rollup Summary Formula or Cross Object Formula fields are updated in the respective objects. (RSF, COF) (These parent records also goes through the entire execution order)
  10. Criteria Based Sharing rules are evaluated (CBS)
  11. Any Post-Commit Logic is executed (PCL)  (like sending an email)

To remember this sequence you can memorise the following.

SV -> BT -> CV -> AT -> AR -> ARR -> WR (BT, AT) -> ER -> RSFCOF -> CBS -> PCL

Being aware of this sequence will help you configure your apps correctly and troubleshoot.

For example say there is a Lead assignment rule defined in Salesforce that assigns all leads to user “Ben Stuart”. Then there is a workflow rule with field update action defined that sets the owner of lead to user “Melissa Lee”. Now when a new Lead is created, the owner of the lead will appear as “Ben Stuart” as Salesforce will first run the lead assignment rule and set the owner to “Ben Stuart” and then it will run the workflow rule and set the owner to “Melissa Lee”. So the final outcome is that the lead owner is “Melissa Lee”

If you are running into issues where the system  is not behaving the way you expect it to, the best way to diagnose and troubleshoot will be to turn the debug on (Setup -> Monitor -> Logs -> Debug Logs), execute the transaction and then check the debug log. Based on the example given above, here is what you will see in the debug log (click on image to enlarge).

Diagnose the Order of Execution in Salesforce with Debug Log