Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Salesforce Order of Execution: A Complete Guide

As one of the most prominent cloud-based customer relationship management (CRM) platforms, Salesforce is renowned for its flexibility and robust features, enabling businesses to manage customer data and interactions efficiently. However, to truly maximize Salesforce’s potential, it is crucial to grasp how the platform processes the information entered by users. 

The order of execution is a vital aspect of Salesforce, referring to the sequence of events that transpire when a user performs a DML or triggers automation in Salesforce. This order defines the platform’s processing rules when handling a user’s request. Comprehending the order of execution is essential for architects, developers, administrators, and anyone working with Salesforce.

In this blog, we will delve into the Salesforce order of execution, its various stages, and its impact on the platform’s behavior.

What is the Order of Execution in Salesforce?

The order of execution refers to the sequence of events that Salesforce follows when processing a user’s request. Every time a user interacts with Salesforce, the platform follows rules to process their request. These rules are predefined and determine how Salesforce will handle the user’s input. The order of execution plays a vital role in determining the outcome of the user’s request.

Understanding the Salesforce Order of Execution Stages:

Let’s take a closer look at each stage of the order of execution and understand how it operates.

Before the events execute on the server, javascript validations are executed on the browser. After that events execute on a server in the below-given order.

Stage 1: Load the Data

Salesforce loads or initializes the Record from the database. Salesforce also loads the new record with the provided new values by overriding the old values.

Stage 2: Identify the Request

Salesforce identifies the source of the request. The source can be standard UI pages, custom UI pages, SOAP Api or REST api. Based on the source of the request, different validation checks are performed.

Stage 3: Execute Record Triggered Flows

Salesforce executes Record Triggered flows which are created to run before the record is saved. 

Stage 4: Execute Before Triggers

Salesforce executes all the Before triggers i.e. before insert or before update or before delete triggers. So, any logic written in the Before triggers will execute at this stage.

Stage 5: Validate the Data

Once the Before Triggers have been executed, Salesforce will execute all the system and custom validations.

Stage 6: Duplicate Rules

After the validation, Salesforce runs the Duplicates rules on the record in context. The most important thing is if the Duplicate rules are configured with the Block action, then Order of execution will stop at this stage.

Stage 7: Save the Record

After the Duplicates rules, Salesforce will Save the record but will not commit it to the database. Record will only be committed when the record in context has successfully completed the order of execution without any failure. 

Stage 8: Execute After Triggers

After the record is saved, Salesforce executes any After Triggers i.e. after insert, after update, after delete So, any logic written in the After triggers will execute at this stage

Stage 9: Execute Assignment Rules

If the record is an object that supports assignment rules, Salesforce executes the Assignment Rules at this stage. Assignment rules specify how records should be assigned to users or queues. These rules can be based on various criteria, such as record type, region, or priority. 

Also Read – Lead Assignment Rules in Salesforce

Stage 10: Execute Auto-Response Rules

If the record is an object that supports auto-response rules, Salesforce executes the Auto-Response Rules at this stage. Auto-Response Rules specify how records should be automatically responded to, such as by sending an email or a text message. 

Stage 11: Execute Workflow Rules

If the record is an object that supports Workflow Rules, Salesforce executes the Workflow Rules at this stage. If the Workflow rules have a field update then record is updated again, system and custom validation rules are executed again and finally run the before the update and after update triggers are one more time (but only one more time)

Stage 12: Escalations Rules

If the record is an object that supports Escalation Rules, Salesforce executes the Escalation Rules at this stage. Escalation rules specify how records should be escalated to higher authorities, such as managers or executives if they are not processed within a certain time frame.

Stage 13: Execute Flows

If the record is an object that supports Lightning Flows and Processes, Salesforce executes them at this stage. The order in which Flows will execute is as per system behavior and your configuration. 

Stage 14: Execute After Record Triggered Flows

At this stage, Salesforce runs the record-triggered flows which are created to run after the record is saved.

Stage 15: Execute Entitlement Rules 

If the record is an object that supports Entitlement Rules, Salesforce executes the Entitlement Rules at this stage. 

Stage 16: Rollup Summary Fields

If the parent record or grand parent records contain rollup summary fields, then once the value is calculated the record goes through the save procedure cycle again.

Stage 17: Criteria-Based Sharing Rules

At this stage, Salesforce will check and execute all the Criteria Based Sharing Rules

for all the records in context to make sure the records are shared correctly.

Stage 18: Record Commit

After finishing all the above events on the server, Salesforce will finally commit the record in the database.

Stage 19: Post-Commit Logic

Once all the previous stages have been completed, Salesforce executes any Post-Commit Logic. Post-Commit Logic includes any custom code blocks developers have created to run after a record has been committed to the database. These code blocks can perform various actions, such as generating reports, updating external systems, or sending notifications, sending emails, invoking async jobs, etc.

Also Read – Salesforce Trigger Frameworks: A Comprehensive Guide

Why is Understanding the Order of Execution Important?

Understanding the order of execution is essential for anyone working with Salesforce. Here are some reasons why:

  1. Prevent Data Loss: Understanding the order of execution can help prevent data loss. For example, suppose a user updates a record and triggers a workflow rule that updates a field. In that case, it is essential to know the order of execution to prevent overwriting the user’s input.
  2. Improve Performance: Understanding the order of execution can help improve performance. For example, if a user performs an action that triggers multiple workflows, it is essential to know the order of execution to optimize the workflow’s performance.
  3. Ensure Compliance: Understanding the order of execution can help ensure compliance. For example, suppose a user performs an action that triggers a validation rule. In that case, it is essential to know the order of execution to ensure that the data entered by the user meets the specified criteria.
  4. Debugging: Understanding the order of execution can help with debugging. For example, if a user performs an action that results in an error, it is essential to know the order of execution to debug the error and fix the issue.

World Class Learning Experience from Anywhere

Download the app now and get started with your Cert Prep Journey!



Summing Up

Understanding the Salesforce order of execution is crucial for any developer or administrator working with the platform. It’s like knowing the game’s rules before you start playing, and it can help you avoid any surprises along the way.

By keeping in mind the different phases of the order of execution, and the specific actions that take place within each one, you can optimize your code and ensure that it runs smoothly and efficiently.

If you are interested in amplifying your Salesforce skills, consider enrolling in the Salesforce Job Guarantee Bootcamp Program by saasguru. Become 3X Salesforce certified and job-ready with our comprehensive program. Our graduates have witnessed an impressive average salary hike of 112%, a testament to the effectiveness of our curriculum.  Start your upskilling journey with us today!

Moreover, to enhance your learning journey and keep crucial resources at your fingertips, download our top-rated Salesforce learning app for your Android or iOS device. Immerse yourself in Salesforce learning anytime, anywhere.

The post Salesforce Order of Execution: A Complete Guide appeared first on saasguru.



This post first appeared on Saasguru Official, please read the originial post: here

Share the post

Salesforce Order of Execution: A Complete Guide

×

Subscribe to Saasguru Official

Get updates delivered right to your inbox!

Thank you for your subscription

×