In this blog post we will learn order of execution in Salesforce.
When a record is created or updated in Salesforce, it undergoes a series of structured steps that ensure data integrity, validation, and automation. Below is a breakdown of the order in which these actions occur:
1. Initial Record Load
The process begins by loading the initial record.
2. System Validation
If the request originates from a standard user interface (UI) edit page, Salesforce performs system-level validations. These checks include ensuring that the record adheres to page layout-specific rules, field definitions, and maximum field lengths.
3. Before-Record Triggered Flows
Any before-record-triggered flows are executed at this point.
4. Before Triggers
All before triggers are executed. These allow for modifications or validations of the record before it's saved.
5. Custom Validation Rules
Salesforce executes custom validation rules to ensure the record meets any business-specific criteria.
6. Duplicate Record Check
Duplicate rules are run to check for any potential duplicate records based on the defined criteria.
7. Record Saved to Database (but not committed)
The record is saved to the database, though it is not yet committed. This means it is in a "pending" state and can still be modified by subsequent actions.
8. After Triggers
All after triggers are executed. These actions occur after the record is saved to the database but before it’s fully committed.
9. Assignment Rules
Assignment rules are evaluated and executed, typically to assign the record to a specific user or queue based on predefined conditions.
10. Auto-Response Rules
If applicable, auto-response rules are triggered, which typically involve sending automated email responses.
11. Workflow Rules
Workflow rules are evaluated next. These rules may trigger actions such as sending email alerts, creating tasks, or updating fields.
12. Workflow Field Updates
If workflow field updates are triggered, Salesforce updates the record again with the new field values.
13. Duplicate Record Check (Re-run)
Because workflow field updates may cause changes that create potential duplicates, Salesforce will re-run the duplicate rules to ensure data integrity.
14. Before Update Triggers and After Update Triggers
If the record was modified due to workflow field updates, Salesforce fires the before update and after update triggers again—once and only once. However, custom validation rules are not re-executed at this stage.
15. Escalation Rules
Escalation rules are applied, typically in cases or service processes, to ensure that records are escalated if certain conditions are met (e.g., if a case isn't resolved in a timely manner).
16. Flow Automation
Salesforce Flow automations are executed at this stage:
Processes: Flows launched by processes are executed.
Flows Triggered by Workflow Rules: Flows launched via workflow rules are triggered (if this feature is enabled in your Salesforce instance).
Record-Triggered Flows: Flows configured to run after a record is saved are executed here.
17. Entitlement Rules
Entitlement rules are checked and executed. These are typically used for managing service-level agreements (SLAs) and entitlements related to cases.
18. Roll-Up Summary Field Calculations
If the record contains a roll-up summary field or is part of a cross-object workflow, Salesforce calculates and updates the corresponding roll-up summary fields on the parent record. The parent record then undergoes the save procedure.
19. Grandparent Record Updates
If the parent record is updated and there is a grandparent record with a roll-up summary field or a cross-object workflow, the system performs calculations and updates the grandparent’s roll-up summary field. The grandparent record will go through the save procedure as well.
20. Criteria-Based Sharing Evaluation
Salesforce evaluates criteria-based sharing rules to determine record visibility and access levels based on predefined criteria.
21. Database Commit
At this point, all DML operations (Data Manipulation Language) are committed to the database, finalizing the record changes.
22. After-Commit Logic
Finally, Salesforce executes after-commit logic, which may include tasks like sending emails, initiating asynchronous Apex jobs, or triggering asynchronous paths in record-triggered flows.
Conclusion:
This detailed order of execution ensures that all necessary validations, processes, and automations are handled in a structured way. By understanding this sequence, Salesforce administrators and developers can better plan and optimize business logic, ensuring smooth data operations and automated processes.
When a record is created or updated in Salesforce, it undergoes a series of structured steps that ensure data integrity, validation, and automation. Below is a breakdown of the order in which these actions occur:
1. Initial Record Load
The process begins by loading the initial record.
2. System Validation
If the request originates from a standard user interface (UI) edit page, Salesforce performs system-level validations. These checks include ensuring that the record adheres to page layout-specific rules, field definitions, and maximum field lengths.
3. Before-Record Triggered Flows
Any before-record-triggered flows are executed at this point.
4. Before Triggers
All before triggers are executed. These allow for modifications or validations of the record before it's saved.
5. Custom Validation Rules
Salesforce executes custom validation rules to ensure the record meets any business-specific criteria.
6. Duplicate Record Check
Duplicate rules are run to check for any potential duplicate records based on the defined criteria.
7. Record Saved to Database (but not committed)
The record is saved to the database, though it is not yet committed. This means it is in a "pending" state and can still be modified by subsequent actions.
8. After Triggers
All after triggers are executed. These actions occur after the record is saved to the database but before it’s fully committed.
9. Assignment Rules
Assignment rules are evaluated and executed, typically to assign the record to a specific user or queue based on predefined conditions.
10. Auto-Response Rules
If applicable, auto-response rules are triggered, which typically involve sending automated email responses.
11. Workflow Rules
Workflow rules are evaluated next. These rules may trigger actions such as sending email alerts, creating tasks, or updating fields.
12. Workflow Field Updates
If workflow field updates are triggered, Salesforce updates the record again with the new field values.
13. Duplicate Record Check (Re-run)
Because workflow field updates may cause changes that create potential duplicates, Salesforce will re-run the duplicate rules to ensure data integrity.
14. Before Update Triggers and After Update Triggers
If the record was modified due to workflow field updates, Salesforce fires the before update and after update triggers again—once and only once. However, custom validation rules are not re-executed at this stage.
15. Escalation Rules
Escalation rules are applied, typically in cases or service processes, to ensure that records are escalated if certain conditions are met (e.g., if a case isn't resolved in a timely manner).
16. Flow Automation
Salesforce Flow automations are executed at this stage:
Processes: Flows launched by processes are executed.
Flows Triggered by Workflow Rules: Flows launched via workflow rules are triggered (if this feature is enabled in your Salesforce instance).
Record-Triggered Flows: Flows configured to run after a record is saved are executed here.
17. Entitlement Rules
Entitlement rules are checked and executed. These are typically used for managing service-level agreements (SLAs) and entitlements related to cases.
18. Roll-Up Summary Field Calculations
If the record contains a roll-up summary field or is part of a cross-object workflow, Salesforce calculates and updates the corresponding roll-up summary fields on the parent record. The parent record then undergoes the save procedure.
19. Grandparent Record Updates
If the parent record is updated and there is a grandparent record with a roll-up summary field or a cross-object workflow, the system performs calculations and updates the grandparent’s roll-up summary field. The grandparent record will go through the save procedure as well.
20. Criteria-Based Sharing Evaluation
Salesforce evaluates criteria-based sharing rules to determine record visibility and access levels based on predefined criteria.
21. Database Commit
At this point, all DML operations (Data Manipulation Language) are committed to the database, finalizing the record changes.
22. After-Commit Logic
Finally, Salesforce executes after-commit logic, which may include tasks like sending emails, initiating asynchronous Apex jobs, or triggering asynchronous paths in record-triggered flows.
Conclusion:
This detailed order of execution ensures that all necessary validations, processes, and automations are handled in a structured way. By understanding this sequence, Salesforce administrators and developers can better plan and optimize business logic, ensuring smooth data operations and automated processes.
No comments:
Post a Comment