
Salesforce Order of Execution

Table of Contents
- What is Order of Execution?
- Order of Execution Stages
- Order of Execution Steps
- What happens in the after commit logic?
- Concise example
- Why is it Important?
- Top 5 Considerations
In this article, we’re going to look at how Salesforce works when you save a record using insert, update, or upsert actions. It’s important for Salesforce Admins who set up automated tasks and for developers who write trigger code to understand this process. Both roles will come together and impact each other, so knowing how Salesforce handles these operations on the inside is key.
What is Order of Execution?
The Order of Execution in Salesforce refers to the specific sequence in which Salesforce processes various steps when a record is saved. This includes actions like insert, update, or upsert (which is a combination of insert and update). Understanding this order is crucial because it determines how the system applies automation rules, validations, and code that can affect the data being saved. For instance, it starts with checking system-level validations, then moves on to execute automation like workflows or triggers, and ends with committing the record to the database. This sequence ensures data integrity and that all business logic is correctly applied.
Knowing the Order of Execution helps Salesforce Admins and developers design efficient and error-free automation and custom code. For Admins, it’s about setting up processes that run in a predictable manner, while for developers, it ensures that the custom code they write, such as triggers, works harmoniously with Salesforce’s built-in processes. By following this order, they can avoid common pitfalls like validation errors or unexpected behavior in automated processes, leading to a smoother and more reliable use of the Salesforce platform.
Join our Salesforce training in Hyderabad to gain practical, hands-on experience.
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.
Read more:Â Salesforce Senior Business Analyst Interview Questions
Initial Client-Side Validation
Before the events execute on the server, JavaScript validations are executed on the browser. These client-side validations are essential for providing immediate feedback to users and ensuring that the data meets basic requirements before it is sent to the server. This step helps in reducing unnecessary server calls and improving overall user experience. Once these validations are complete, events execute on the server in the following order.
Stage 1: Load the Data
Load the Data Salesforce begins the server-side order of execution by loading or initializing the record from the database. This means that the current state of the record is retrieved, including all existing values. If a new record is being created, Salesforce initializes the record with the new values provided in the request. During this stage, any new values sent with the request will override the existing values in the database. This initialization sets the foundation for all subsequent operations and ensures that the record is in the correct state before any further processing occurs.
Read more:Â Roles and Profiles in Salesforce Interview Questions
Stage 2: Identify the Request
Identify the Request At this stage, Salesforce identifies the source of the request. The request can originate from various sources, such as standard UI pages, custom UI pages, SOAP API, or REST API. Identifying the request source is crucial because it determines the type of validation and processing that will follow. For example, requests from standard UI pages may have different validation requirements compared to those coming from custom pages or APIs. This step ensures that the appropriate validation checks are performed based on the context in which the request was made.
Read more:Â Accenture Salesforce Developer Interview Questions
Stage 3: Execute Record Triggered Flows
Execute Record Triggered Flows Salesforce executes any Record Triggered flows that are configured to run before the record is saved. These flows are automated processes designed to perform specific actions based on certain criteria. They are an essential part of the automation capabilities within Salesforce and can include tasks such as updating fields, sending emails, or creating related records. Record Triggered flows allow for complex business logic to be executed automatically, ensuring that necessary actions are taken before the record proceeds to the next stage of the order of execution.
Stage 4: Execute Before Triggers
Execute Before Triggers Before triggers are executed next. These triggers run before a record is inserted, updated, or deleted in the database. This stage is critical for implementing custom logic that needs to be applied to a record before any changes are committed. For example, you might use a before trigger to populate a field automatically, enforce custom validation rules, or modify related records. By executing these triggers before the actual database operation, Salesforce ensures that all necessary pre-processing logic is applied, maintaining data integrity and consistency.
Read more:Â Salesforce Service Cloud Interview Questions
Stage 5: Validate the Data
Validate the Data Once the Before Triggers have been executed, Salesforce’s system validation mechanisms come into play. This stage involves running both standard system validations and any custom validation rules defined by the user. Standard validations include checks for required fields, data type consistency, and field format. Custom validations might involve more complex business rules specific to an organization’s needs. These validations ensure that the data adheres to predefined standards and business logic before it is processed further. If any validation fails, an error is thrown, and the record is not saved.
Read more:Â Salesforce Data Loader Interview Questions and Answers
Stage 6: Duplicate Rules
Duplicate Rules After successful validation, Salesforce runs Duplicate Rules on the record in context. Duplicate Rules are designed to prevent the creation of duplicate records, which can clutter the database and lead to data integrity issues. If the Duplicate Rules are configured with the Block action, the order of execution stops at this stage, preventing the record from being saved. Alternatively, if the Duplicate Rules allow for alerts or reports, the process continues, but the user is notified of potential duplicates. This stage is crucial for maintaining clean and reliable data within Salesforce.
Read more:Â TCS Salesforce Interview Questions
Stage 7: Save the Record
Save the Record Once the Duplicate Rules have been applied, Salesforce proceeds to save the record. However, this initial save does not commit the record to the database yet. Instead, the record is temporarily saved while Salesforce continues to run subsequent operations. This staged approach ensures that any errors or issues that arise later in the execution order can be addressed before the final commit. The record will only be permanently committed to the database once it successfully completes the entire order of execution without any failures or conflicts. This step provides a safeguard, ensuring data integrity.
Read more:Â Important Salesforce Experience Cloud Interview Questions
Stage 8: Execute After Triggers
Execute After Triggers After the record is saved temporarily, Salesforce executes any After Triggers. These triggers run after the record has been inserted, updated, or deleted. After Triggers are used to perform operations that depend on the record’s saved state. This can include updating related records, sending notifications, or triggering other processes. By executing these triggers after the initial save, Salesforce ensures that all dependent actions are based on the final state of the record, which helps maintain consistency across related data and processes within the system.
Stage 9: Execute Assignment Rules
Execute Assignment Rules If the record is an object that supports assignment rules, Salesforce executes the Assignment Rules at this stage. Assignment Rules determine how records are assigned to users or queues. These rules can be based on various criteria such as record type, region, or priority. For instance, leads might be assigned to different sales representatives based on geographic regions, or cases might be routed to different support queues based on issue type. This automated assignment process ensures that records are directed to the appropriate team members or departments efficiently, improving workflow and productivity.
Read more:Â Salesforce Service Cloud Interview Questions
Stage 10: Execute Auto-Response Rules
Execute Auto-Response Rules If the record is an object that supports Auto-Response Rules, Salesforce executes these rules at this stage. Auto-Response Rules define how the system should automatically respond to specific conditions, such as sending an email or text message to the record owner or related contacts. This automated communication ensures timely and consistent responses, enhancing customer engagement and operational efficiency.
Read more:Â Salesforce Data Architect Interview Questions with Answers
Stage 11: Execute Workflow Rules
Execute Workflow Rules When workflow field updates occur, Salesforce processes these updates as follows:
- Perform Another Update on the Record: The system updates the record based on the workflow rules defined.
- Re-run System Validations: System validations are executed again to ensure data integrity. However, custom validation rules, flows, duplicate rules, processes, and escalation rules will not be re-executed during this phase.
- Execute Before and After Update Triggers Once More: Before and after update triggers are executed again, whether it’s an insert or update operation. However, each trigger is only run once in this stage to prevent infinite loops and ensure stable execution.
Stage 12: Execute Escalation Rules
Execute Escalation Rules If the record is an object that supports Escalation Rules, Salesforce executes these rules at this stage. Escalation Rules determine how records should be escalated to higher authorities, such as managers or executives, if they are not processed within a specified time frame. This mechanism ensures that critical issues are addressed promptly and do not remain unresolved, thereby maintaining efficient workflow and high levels of service.
Salesforce Advanced Admin Interview Questions and Answers
Stage 13: Execute Flows
Execute Flows At this stage, Salesforce executes Lightning Flows and Processes if the record is an object that supports them. Flows are powerful automation tools that allow you to build complex business logic without writing code. They can be triggered by various events, such as record creation, updates, or deletions. The order in which Flows execute depends on the system’s internal behavior and your specific configuration.
Example: Imagine a scenario where a Flow is set up to automate the onboarding process for new employees. When a new Employee record is created, the Flow automatically assigns a mentor, sets up the necessary system access, and sends a welcome email. This Flow ensures that the onboarding process is consistent and efficient.
Read more:Â Roles and Profiles in Salesforce Interview Questions
Stage 14: Execute After Record-Triggered Flows
Execute After Record-Triggered Flows At this stage, Salesforce runs the record-triggered flows that are designed to execute after the record is saved. These flows are essential for performing post-save operations, such as updating related records, sending notifications, or performing complex calculations.
Example: Consider a case where an After Record-Triggered Flow updates the account’s Total Purchase Amount field whenever a new Order record is saved. This ensures that the account information is always up-to-date, reflecting the latest transactions automatically.
Stage 15: Execute Entitlement Rules
Execute Entitlement Rules If the record is an object that supports Entitlement Rules, Salesforce executes these rules at this stage. Entitlement Rules define the terms and conditions under which customers are provided with service or support. They ensure that the service level agreements (SLAs) are adhered to by automating the process of checking entitlements and applying appropriate actions.
Example: In a customer support scenario, Entitlement Rules can be used to determine if a customer is eligible for premium support based on their subscription level. When a Case record is created, the Entitlement Rules check the customer’s subscription and route the case to the appropriate support team, ensuring that high-priority customers receive expedited service.
Read more:Â API suffixes in Salesforce
Stage 16: Rollup Summary Fields
Rollup Summary Fields If the parent or grandparent records contain rollup summary fields, Salesforce calculates the value of these fields at this stage. Rollup summary fields are used to display aggregate values, such as the sum, minimum, maximum, or count of related child records. Once these values are calculated, the record goes through the save procedure cycle again to ensure that all related records are updated accordingly.
Example: Consider a scenario where an Account record has a rollup summary field that calculates the total value of all associated Opportunity records. When a new Opportunity is created or an existing one is updated, the rollup summary field on the Account recalculates the total value. This ensures that the Account record always reflects the correct total of its related Opportunities.
Stage 17: Criteria-Based Sharing Rules
Criteria-Based Sharing Rules At this stage, Salesforce checks and executes all Criteria-Based Sharing Rules for the records in context. Criteria-Based Sharing Rules determine how records should be shared with users based on specific conditions or criteria. This ensures that records are shared correctly and that the right users have access to the necessary data.
Example: Suppose a company uses Criteria-Based Sharing Rules to share Opportunity records with sales managers based on the Opportunity’s region and deal size. When an Opportunity meets the specified criteria (e.g., located in the West region and deal size over $100,000), it is automatically shared with the appropriate sales managers. This ensures that high-value deals are visible to senior sales staff for better oversight and management.
Read more:Â Salesforce CPQ Interview Questions and Expert Answers
Stage 18: Record Commit
Record Commit After completing all the preceding events and validations on the server, Salesforce finally commits the record to the database at this stage. This means that all changes made to the record are saved permanently. The commit operation ensures that the data is consistent and that all the updates and triggers that have been executed up to this point are finalized. This step is crucial for maintaining the integrity of the database and ensuring that all changes are accurately recorded.
Example: When an Opportunity record goes through the entire order of execution, including validations, triggers, and flows, it is finally committed to the database. This commit operation solidifies all the changes, such as updated amounts, status changes, and related updates, making them permanent in the system.
Read more:Â String methods in Salesforce apex
Stage 19: Post-Commit Logic
Post-Commit Logic Once the record has been committed to the database, Salesforce executes any Post-Commit Logic. Post-Commit Logic includes custom code blocks that developers have created to run after the record has been saved. These code blocks can perform a variety of actions, such as generating reports, updating external systems, sending notifications, sending emails, and invoking asynchronous jobs. This stage allows for additional processing that depends on the record being successfully committed.
Example: After an Account record is committed to the database, a Post-Commit Logic block might be set up to send a welcome email to the new account owner, generate a report for the sales team, and trigger an asynchronous job to update related records in an external ERP system. This ensures that all necessary follow-up actions are taken after the record is securely saved.
Order of Execution Steps:
The order of execution in Salesforce when a record is saved (insert, update, or upsert statement) involves several steps. Here is a brief overview:
- Load the initial record from the database.
- Run system validations for standard UI edit pages.
- Execute before record-triggered flows.
- Execute all before triggers.
- Run most custom validations.
- Execute duplicate rules.
- Save the record to the database (without committing).
- Execute all after triggers.
- Run assignment rules.
- Execute auto-response and workflow rules.
- Execute escalation rules.
- Execute post-save Salesforce Flow automations.
- Update roll-up summary fields if applicable.
- Execute Criteria Based Sharing evaluation.
- Commit all DML operations to the database.
- Execute after-commit logic (emails, asynchronous Apex, etc.).
Read more: Top Salesforce interview questions
What happens in the after commit logic?
In Salesforce, the after commit logic refers to operations that are executed after the database transaction is committed. This means these actions take place after Salesforce has saved all changes to the database and ensured data integrity and consistency. The after commit phase is crucial because it includes steps that should only run once the record is securely saved and the transaction cannot be rolled back.
Some examples of operations that occur in the after commit phase include sending out email notifications, executing post-commit logic in Apex triggers (if specifically designed to do so), and processing any outbound messages that are configured to be sent to external systems. This phase ensures that any side effects of the record save operation, like notifications or integrations with other systems, are handled after the data is confirmed to be saved, minimizing the risk of sending out notifications or messages based on transactions that could potentially fail or be rolled back earlier in the order of execution.
Read more: Salesforce Admin tutorial for beginners
Here’s a concise example of Salesforce’s order of execution:
Imagine you have a Salesforce record, say an Account record, that you are updating through a standard UI edit page. When you save this record, Salesforce first loads the initial record from the database. Next, it runs system validations like checking for page layout-specific rules and field lengths. Then, it executes any before record-triggered flows and before triggers. Custom validations and duplicate rules are run, followed by saving the record to the database (without committing).
Subsequently, after triggers are executed. This is followed by the running of assignment, auto-response, and workflow rules. If there are workflow field updates, the record might be updated again, re-triggering certain steps like duplicate rules and after triggers. Finally, after-commit logic such as sending emails or executing asynchronous Apex jobs is processed, and the DML operations are committed to the database.
This example demonstrates how multiple layers of validation, triggers, and rules interact during the record saving process in Salesforce.
}
Read more: Triggers in Salesforce interview Questions
Why is Understanding the Order of Execution Important?
1. Ensuring Data Integrity
Understanding the order of execution helps maintain data integrity by ensuring that all necessary validations and rules are applied correctly before a record is saved. This prevents data corruption and ensures that the database remains consistent.
2. Implementing Custom Logic
Developers can effectively implement custom logic within triggers, flows, and validation rules by knowing the precise order of execution. This ensures that the logic executes at the right stage without causing conflicts or unintended side effects.
Read more :Â Salesforce cpq interview questions part 2
3. Debugging and Troubleshooting
When issues arise, understanding the order of execution is crucial for debugging and troubleshooting. It allows developers to identify at which stage an error occurs and to apply targeted fixes, improving the overall reliability of the system.
4. Optimizing Performance
By knowing the sequence of operations, developers can optimize performance by minimizing redundant processing and ensuring that the most critical validations and triggers execute efficiently. This helps in improving the system’s responsiveness and scalability.
5. Compliance with Business Rules
Understanding the order of execution ensures that all business rules and policies are enforced correctly. This is vital for maintaining compliance with organizational standards and external regulations, reducing the risk of errors and legal issues.
Read more:Â Guided Selling in Salesforce CPQ
6. Effective Use of Automation
Automation tools like workflows, processes, and flows can be effectively used when the order of execution is well understood. This enables seamless automation of complex business processes, reducing manual intervention and increasing efficiency.
7. Accurate Data Sharing
The correct execution of criteria-based sharing rules depends on understanding the order of execution. This ensures that records are shared appropriately based on defined criteria, maintaining data security and access control.
8. Preventing Data Loss
Proper knowledge of the order of execution helps prevent data loss by ensuring that all necessary steps are completed before a record is committed to the database. This is particularly important for critical business data that requires high accuracy.
9. Enhancing User Experience
A smooth and predictable order of execution enhances the user experience by ensuring that data is processed correctly and efficiently. This reduces the likelihood of errors and delays, leading to a more reliable and user-friendly application.
10. Supporting Complex Business Scenarios
Complex business scenarios often require multiple interconnected steps. Understanding the order of execution allows developers to design and implement workflows that handle these scenarios effectively, ensuring that all interdependencies are managed correctly.
Top 5 Considerations for Understanding the Order of Execution
1. Ensuring Data Integrity
Understanding the order of execution is crucial for maintaining data integrity within Salesforce. It ensures that all necessary validations, triggers, and rules are applied in the correct sequence before a record is saved. This prevents data corruption and ensures that the database remains consistent and reliable.
2. Implementing Custom Logic
By knowing the precise order of execution, developers can effectively implement custom logic within triggers, flows, and validation rules. This ensures that the custom logic executes at the right stage without causing conflicts or unintended side effects, allowing for seamless and accurate data processing.
3. Debugging and Troubleshooting
When issues arise, understanding the order of execution is essential for debugging and troubleshooting. It allows developers to pinpoint at which stage an error occurs and to apply targeted fixes. This knowledge significantly improves the reliability and stability of the system, making it easier to resolve issues quickly and efficiently.
4. Optimizing Performance
Knowing the sequence of operations helps developers optimize performance by minimizing redundant processing and ensuring that the most critical validations and triggers execute efficiently. This optimization leads to better system responsiveness, scalability, and overall performance, which is essential for handling large volumes of data and complex processes.
5. Compliance with Business Rules
Understanding the order of execution ensures that all business rules and policies are enforced correctly. This is vital for maintaining compliance with organizational standards and external regulations. Ensuring that business rules are applied at the right stages reduces the risk of errors and legal issues, providing a solid foundation for reliable business operations.
CRS Info Solutions offers a comprehensive Salesforce training program tailored to boost your skills and career prospects. Join our Salesforce training in Hyderabad to gain practical, hands-on experience. Our program covers all crucial aspects of Salesforce, ensuring an in-depth learning experience.
With experienced instructors and a detailed curriculum, CRS Info Solutions is dedicated to your success in the Salesforce ecosystem through our Career Building program. Whether you’re a beginner or seeking to enhance your skills, we provide the guidance and resources you need. Enroll in our free demo today!

