top of page
Search
Writer's pictureDeepak

Order of Execution in Salesforce

Updated: Jul 6, 2020

What is the Salesforce order of execution?


When you save, update, or upsert a record, the salesforce engine executes all its logics related to the statement one by one. The order in which Salesforce execute its logic is called the order of execution. As these statements are very tied to each other, it impacts others internally as well.



Order of Execution Flow in Salesforce


Before Salesforce Order of execution starts, Salesforce check(JavaScript validation) if any dependent picklists available or not, if yes Salesforce enables that picklist in dropdown.


Order of execution in Salesforce gets initiated on click of save button, with the following event than after.


Order of Execution in Salesforce


  • DML Operation Starts

  • System Validation

  • Before Triggers

  • Custom Validation

  • System Validation

  • Duplicate Rules

  • Write and Update Record

  • After triggers

  • Assignment Rules

  • Auto-response Rules

  • Workflow Rules( Before Triggers -> System Validation -> After Triggers)

  • Processes Builder and Flow Action(Before Triggers -> System Validation -> After Triggers)

  • Escalation Rules

  • Entitlement Rules

  • Cross Object Workflow for Parent Object

  • Parent Rollup Summary

  • Cross Object Workflow for Grand-Parent

  • Grand-Parent Rollup Summary

  • Criteria Based Sharing Rules

  • Data Base Commit

  • Post DML Logics, such as Sending Emails


Demystifying Order of Execution in the Salesforce one by one


  • Order of Execution start with initialization of record, it can be either of insert or update or upsert operations. Here old values are overriden by new values,

If request comes from Standard UI edit page then Salesforce execute System Validation checks for records such as :


-> Compliance with layout-specific rules.

-> Required values at layout lavel and field definition level.

-> Validate field format.

-> Maximum field length.


If request comes from SOAP API

-> Salesforce validates only the foreign keys, it check if custom foreign key does not refer to object itself

  • Executes all before triggers

  • System Validates all except enforcement of layout specific rules.

  • User-defined validation rules also called as Custom Validation

  • Execution of Duplicate Rules to check if any duplicate rcords are there, if found duplicate records, execution stops here, role-back.

  • Save the records to database. Save is very different than Commit. It gives you Salesforce record id only but does not commit the record to database.

  • Executes all after triggers

  • Executes assignment rules.

  • Executes auto-response rules.

  • Executes workflow rules.

  • If there are workflow field updates, updates the record again.

  • If the record update trigger before update triggers and after update triggers, then it will execute again one more time (and only one more time). Here System Validation was executed again with followed by after triggers. Here no other validation executes such as (no custom validation, no duplicates rules ..etc).

  • The refiring of triggers isn't limited to updates, but applies to all operation types. A workflow field update that fires on record insert will rerun any before and after insert triggers again—as insert triggers.

  • Executes processes and flows launched via processesand flow trigger workflow actions.When a process or flow executes a DML operation, the affected record goes through the save procedure.

  • Executes escalation rules.

  • Executes entitlement rules.

  • If the record contains a roll-up summary field or is part of a cross-object workflow, performs calculations and updates the roll-up summary field in the parent record. Parent record goes through save procedure.

  • If the parent record is updated, and a grandparent record contains a roll-up summary field or is part of a cross-object workflow, performs calculations and updates the roll-up summary field in the grandparent record. Grandparent record goes through save procedure.

  • Executes Criteria Based Sharing evaluation.

  • Commits all DML operations to the database.

  • Executes post-commit logic, such as sending email.

Salesforce Order of Execution has few loop holes, in certain situations. So it is always adviable to follow standard and best practices to avaoid any issues in order of exection.



Points must be taken into consideration while expecting correct Salesforce order of exection.

  1. There should be one trigger per object. The order of execution isn’t guaranteed when having multiple triggers for the same object due to the same event.

  2. If an object has multiple active flows that make before-save updates, Salesforce can't guarantee the order in which those flows are executed.

  3. Bulk dml exception.

  4. Additional Considerations for Account and Opportunities.

  5. Trigger.old always carries initial values e.x. suppose existing Opportunity's currency is INR, if a user update this field to USD, a work flow field update fires and update the currency field to EURO, In the update trigger that fires after the workflow field update, the field value of the object obtained fromTrigger.old is the original value INR , rather than USD, as would typically be the case.


Here are some famouse questions on Oder of Execution in Salesfoce


  • Where does Process Builder & Workflow stand in Order of Execution in Salesforce? Or, Which is executed first workflow or process builder?

--> Process builder gets executes after Workflow but before exclation rule.

  • Will Approval process initiate any workflows or Process Builder or Apex Triggers? And, what will be its Order of Execution.

--> Workflow: Does not fires untill Re-evaluate workflow checkbox is ticked on your field update

Process Builder:  Does not fires untill Re-evaluate workflow checkbox is ticked on your field

update, Trigger: Will fire if any of the conditions are matched. There order will be same as

explained above.

  • What do you mean by Salesforce Order of Execution cheat sheet.

--> Please refer above Order of Execution.

  • What is Order of Execution in Salesforce Lightning?

--> Order of Execution is part of DML operation it means any insert, update or upsert happen

even from the lightning page, the Order of Execution will be same(as mentioned above).


  • What are Order of Execution in Validation Rule?

--> Validation rule comes under custom validation, and it gets executes after "before trigger".

Please refer the order from above.



Reference : Salesforce developer blogs on Order of Execution. .

172 views0 comments

Recent Posts

See All

Kommentare


bottom of page