When a record is saved in salesforce with insert, update or upsert statement, salesforce performs below event in sequence behind the scene.
  1. Runs Client side validations: The browser runs javascript to check if there is any dependent picklist field is present. If yes then it prompts user to fill the value or throws error on UI.
  2. Loading/Initializing: Loads the original record from the database or initializes the record for an upsert statement.
  3. Loads the new record field values from the request and overwrites the old values: Say Account’s shipping address is being changed from Pune to Mumbai, then Pune is retrieved from database and its overwritten with value Mumbai
  4. Executes all before triggers.
  5. Runs most system validation steps again: Such as verifying that all required fields have a non-null value, and runs any user-defined validation rules(Say Account’s billing country can’t be left blank). 
  6. Execute Duplicate rules: Duplicate rules are implemented to reduce the potential insertion of Account with the same name.
  7. Saves the record to the database, but doesn’t commit yet: Soft save, not available for SOQL yet.
  8. Executes all after triggers.
  9. Executes assignment rules: Assignment rule is created on Case and Lead object. An assignment rule dictates to whom a lead or case is assigned based on criteria that is specified within Salesforce.
  10. Execute auto-response rules: An auto-response rule is a set of conditions for sending automatic email responses to lead or case submissions based on the attributes of the submitted record.
  11. Executes workflow rules: Workflow lets you automate standard internal procedures and processes to save time across your org. A workflow rule is the main container for a set of workflow instructions. These instructions can always be summed up in an if/then statement.
  12. If there are workflow field updates, updates the record again.
  13. If the record was updated with workflow field updates, fires before update triggers and after update triggers one more time (and only one more time), in addition to standard validations. Custom validation rules, duplicate rules, and escalation rules are not run again.
  14. Executes processes and flows launched via processes and flow trigger workflow actions.
  15. Executes escalation rules: are used to escalate cases automatically when they meet the criteria which are defined in rule entry. We create rule entries where criteria is defined to escalate a case.
  16. Executes entitlement rules.
  17. 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.
  18. Executes Criteria Based Sharing evaluation.
  19. Commits all DML operations: Here the record will be actually saved to database and the transaction will complete.
  20. Executes post logic: Once the record is saved to database, some post logic will be performed like sending mail to customers, updating a formula field etc
5 thoughts on “Salesforce execution sequence”
  1. It?s hard to find knowledgeable people on this topic, but you sound like you know what you?re talking about! Thanks

  2. This is the right blog for anyone who wants to find out about this topic. You realize so much its almost hard to argue with you (not that I actually would want?HaHa). You definitely put a new spin on a topic thats been written about for years. Great stuff, just great!

  3. Hello! I just would like to give a huge thumbs up for the great info you have here on this post. I will be coming back to your blog for more soon.

Leave a Reply

Your email address will not be published. Required fields are marked *