Order of Execution in Salesforce
Updated on 14th Mar, 22 349 Views

As per Gartner, revenue in the Enterprise Software segment is expected to reach more than US$230 million by the end of 2021. Businesses are shifting more and more towards technological CRMs to keep up in today’s tech era.

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

If you are a Salesforce consultant, developer, or architect, it’s essential for you to understand the order in which the rules and triggers are executed. Let’s see the order of execution in Salesforce:

The following topics will be covered in this blog :

What is Order of Execution in Salesforce?

Order of Execution in Salesforce is nothing but a set of rules that govern, or describe the path of a record while it travels through multiple automation and events happening from SAVE to COMMIT. In simpler terms, when you save a record by giving the insert, update, or upsert statement, Salesforce performs certain events in an orderly manner. This is termed the order of execution in Salesforce. The order of execution starts with a DML operation and later there are further involvements like triggers, out-of-the-box Salesforce components, workflows, different rules, etc.

Watch this tutorial on ‘Salesforce Developer Training for Beginners’:

Preparing for a Salesforce Interview! Check out our Top Salesforce Interview Questions and Answers.

Order of Execution in Salesforce

  1. Load the original record from the database and load the record for the upsert statement.
  2. Load the new record field values from the request and overwrite the old values.
    If the request comes from a standard UI edit page, Salesforce runs system validation to check the record for:
    • Compliance with layout-specific rules
    • Required values at the layout level and field-definition level
    • Valid field formats
    • Maximum field length
  3. Whenever a request comes from other sources, e.g., Apex application or a SOAP API call, Salesforce validates only the foreign keys.
  4. Executes record-triggered flows that are configured to run before the record is saved.
Full save cycle
  1. Executes all before triggers.
  2. Run most system validation steps. Verify that all required fields have a non-null value and run user-defined validation rules.
  3. Executes duplicate rules.
  4. Saves the record to the database, but doesn’t commit yet.
  5. Executes all after triggers.
  6. Executes assignment rules.
  7. Executes auto-response rules.
  8. Executes workflow rules.
  9. Executes escalation rules.
  10. If there are workflow field updates, update the record again.
  11. If the record was updated with workflow field updates, fires before update triggers and after update trigger one more time (and only one more time), in addition to standard validations.
  12. Executes processes and flows launched using flow trigger workflow actions.
  13. Executes entitlement rules.
  14. Executes record-triggered flows that are configured to run after the record is saved.
  15. If the record contains a roll-up summary field or is part of a cross-object workflow, perform calculations and update the roll-up summary field in the parent record. Parent record goes through the save procedure.
  16. 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.
  17. Executes Criteria Based Sharing evaluation.
  18. Commits all DML operations to the database.
  19. Executes post-commit logic, such as sending an email.

After Commit Logic?

  1. All emails are sent
  2. Asynchronous apex: @future
  3. Processes Async Sharing Rule
  4. Queues outbound messages
  5. Calculates index
  6. Renders previews for files
  7. If Platform Events are configured, they are published
Become a Salesforce Expert

Enroll today in Salesforce Training in London to get a clear understanding of Salesforce!

Triggers in Salesforce

The two types of Triggers in Salesforce are as follows:

  • Before Triggers – These are executed before the record values are saved to the database.
  • After Triggers – These are used to trigger records that are read-only.

Before or after applying changes to the Salesforce record, you can make customized changes to it. This is enabled by triggers. Triggers can invoke apex. Triggers are executed before or after these operations:

  • undelete
  • upsert
  • merge
  • delete
  • update
  • Insert

Some top-level objects like Account, support triggers. You can define triggers for them. If you want to define a trigger, you can go to that particular object Object Management Settings and go to Triggers.

Which Operations Don’t Invoke Triggers?

  • All the records that didn’t start a delete, don’t invoke triggers
  • Child records that have been reparented using the merge operation
  • Huge email actions, division transfers, address updates
  • Custom field data being modified
  • When you rename or replace a picklist
  • When you change a user’s division that is the default, while the transfer division option is checked
  • Price book management
  • Update account trigger won’t work before/after a user’s account is changed to a business one
  • When the LikeCount counter increases, update triggers won’t work on FeedItem

Also, Check out our blog to learn about Test Class in Salesforce!

Extra Consideration

When you have multiple triggers for the same object due to the same event, the execution of that trigger is not guaranteed. You’ll need to implement Trigger Framework in this case.

Conclusion

As we have discussed in order of execution there is a lot more to understand than triggers run before workflows. Understanding the flow and apps will have more scalability and reliability. Start learning Salesforce and its mechanisms by enrolling in Salesforce Certification Course.

For more information on Salesforce, visit our Salesforce Community!

Course Schedule

Name Date
Salesforce Certification 2022-06-25 2022-06-26
(Sat-Sun) Weekend batch
View Details
Salesforce Certification 2022-07-02 2022-07-03
(Sat-Sun) Weekend batch
View Details
Salesforce Certification 2022-07-09 2022-07-10
(Sat-Sun) Weekend batch
View Details

Leave a Reply

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

Speak to our course Advisor Now !

Related Articles

Subscribe to our newsletter

Signup for our weekly newsletter to get the latest news, updates and amazing offers delivered directly in your inbox.