Training Outcomes Within Your Budget!

We ensure quality, budget-alignment, and timely delivery by our expert instructors.

Share this Resource

Table of Contents

Order of Execution in Salesforce

Let’s assume that you’re troubleshooting a complex Salesforce issue, and you’re unsure why certain triggers aren’t firing as expected. Given this scenario, you might wonder how Salesforce processes your data behind the scenes. However, understanding the Order of Execution in Salesforce can be the key to unlocking these mysteries. This detailed blog will take you through each stage, from initial data loading to post-commit logic. 

By mastering the Order of Execution in Salesforce, you’ll gain insights that can enhance your system’s performance and reliability. Let’s get started!

Table of Contents 

1) What is the Order of Execution?

2) Understanding Order of Execution in Salesforce: Stages

3) Important Considerations and Changes From Flow Behaviour

4) Operations Which do not Include Triggers

5) Conclusion

What is the Order of Execution?

The Order of Execution in the Salesforce Database refers to the sequence of steps followed when processing data and executing operations within the platform. Understanding the order of execution is crucial for developers and administrators as it ensures the integrity and accuracy of data, as well as the proper functioning of various automation processes. 

The Order of Execution in Salesforce can be categorised into three main phases:  

a) Pre-transaction steps 

b) Data processing steps, and  

c) After-transaction steps


Salesforce Admin Course
 

Understanding Order of Execution in Salesforce: Stages  

Let’s examine each stage of the order of execution and understand its operation. Before events execute on the server, JavaScript validations are performed on the browser. Subsequently, events execute on the server in the following order:

Stage 1: Load the Data- Salesforce loads or initialises the record from the database. It also loads the new record with the provided values, overriding the old ones.

Stage 2: Identify the Request- Salesforce identifies the source of the request, which could be standard User Interface (UI) pages, custom UI pages, Simple Object Access Protocol Application Programming (SOAP API), or Representational State Transfer Application Programming (REST API). Different validation checks are performed based on the request source.

Stage 3: Execute Record-triggered Flows- Salesforce executes record-triggered flows designed to run before the record is saved.

Stage 4: Execute Before Triggers- Salesforce executes all ‘before’ triggers, such as before insert, update, or delete triggers. Any logic written in these triggers will execute at this stage.

Stage 5: Validate the Data- Once the ‘before’ triggers have been executed, Salesforce’s system validation mechanisms perform all system and custom validations.

Stage 6: Duplicate Rules- After validation, Salesforce runs the duplicate rules on the record in context. If the duplicate rules are configured with the block action, the order of execution will stop at this stage.

Stage 7: Save the Record- After the duplicate rules, Salesforce saves the record but does not commit it to the database. The record will only be committed if it successfully completes the order of execution without any failure.

Stage 8: Execute After Triggers- After the record is saved, Salesforce executes any ‘after’ triggers, such as after insert, update, or delete triggers. Any logic written in these 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 based on various criteria, such as record type, region, or priority.

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. These 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 workflow field updates occur, you must follow these steps:

Steps to Executing Workflow Rules

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

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 execute depends on system behaviour and your configuration.

Stage 14: Execute After Record-Triggered Flows- At this stage, Salesforce runs the record-triggered flows designed 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 or grandparent records contain rollup summary fields, once the value is calculated, the record goes through the save procedure cycle again.

Stage 17: Criteria-based Sharing Rules- At this stage, Salesforce checks and executes all criteria-based sharing rules for all records in context to ensure they are shared correctly.

Stage 18: Record Commit- After completing all the above events on the server, Salesforce finally commits the record to the database.

Stage 19: Post-commit Logic- Once all previous stages are completed, Salesforce executes any post-commit logic. This 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, sending notifications, emails, or invoking asynchronous jobs.

Enhance your skills and drive your business forward – sign up for our CRM Trainings now!

Important Considerations and Changes From Flow Behaviour

When developing Salesforce triggers, it is crucial to consider specific factors and recent changes in flow behaviour that can significantly impact trigger operations within the Salesforce environment. These elements are vital for ensuring effective data processing and system performance.

a) Behaviour of Trigger.old in Workflow Updates: Trigger.old retains pre-user update values during workflow updates, not the intermediate state post-workflow update.

b) Triggers in Partial DML Operations: Triggers fire with each attempt in partial DML operations, and static variables do not reset within the same transaction.

c) Execution Order of Multiple Triggers: Salesforce does not guarantee the execution order of multiple triggers on the same object for the same event, leading to potential unpredictability.

d) Changes in Flow Execution: Post Salesforce API version 53.0, after-save record-triggered flows execute differently concerning entitlements.

e) Complex Relationships and Execution Context: For operations involving complex relationships, refer to specific Salesforce documentation for nuanced behaviours.

f) Optimising Opportunity Trigger Logic: Understand specific behaviours and best practices for Opportunity triggers to ensure correct functionality and data integrity.

Operations Which do not Include Triggers

There are several operations within Salesforce that do not trigger evaluation. Understanding these exceptions is crucial for developers to ensure accurate system behaviour and data integrity. Below are some key operations where triggers are not fired:

Salesforce Actions That Don’t Trigger Evaluation

a) Records that did not initiate a delete do not trigger evaluation.

b) Child records that were reparented due to a merge operation.

c) Mass campaign status changes, division transfers, address updates, approval request transfers, and email actions.

d) Changing the data type of custom fields

e) Adjusting picklist values

f) Operations related to price books

g) Changing a user’s default division with the transfer division option checked

Join our expert-led Salesforce Developer Training and equip yourself with the latest Salesforce tools.

Conclusion 

Understanding the Order of Execution in Salesforce is crucial for optimising workflows and ensuring seamless data processing. Mastering these stages enhances system performance and maintains data integrity. This knowledge empowers you to troubleshoot issues effectively and implement best practices in your Salesforce environment.

Frequently Asked Questions

Can a Workflow Rule Trigger a Flow or Process Builder? faq-arrow

Yes, a Workflow Rule can trigger a Flow or Process Builder in Salesforce. This allows for more complex automation by initiating flows when specific conditions are met within the Workflow Rule.

Are all Process Automation Executed in a Single Transaction in Salesforce? faq-arrow

No, not all Process Automations are executed in a single transaction. While some can run within the same transaction, others may execute in separate transactions, particularly when involving asynchronous processes, ensuring efficient handling of larger data sets.

What are the Other Resources and Offers Provided by The Knowledge Academy? faq-arrow

The Knowledge Academy takes global learning to new heights, offering over 30,000 online courses across 490+ locations in 220 countries. This expansive reach ensures accessibility and convenience for learners worldwide.

Alongside our diverse Online Course Catalogue, encompassing 19 major categories, we go the extra mile by providing a plethora of free educational Online Resources like News updates, Blogs, videos, webinars, and interview questions. Tailoring learning experiences further, professionals can maximise value with customisable Course Bundles of TKA.
 

What is The Knowledge Pass, and How Does it Work? faq-arrow

The Knowledge Academy’s Knowledge Pass, a prepaid voucher, adds another layer of flexibility, allowing course bookings over a 12-month period. Join us on a journey where education knows no bounds.

What are the Related Courses and Blogs Provided by The Knowledge Academy? faq-arrow

The Knowledge Academy offers various CRM Trainings, including the Salesforce Admin Training, Salesforce Developer Training, and HubSpot CRM Training. These courses cater to different skill levels, providing comprehensive insights into Popular Types of Salesforce Roles.

Our Office Application Blogs cover a range of topics related to Salesforce Execution, offering valuable resources, best practices, and industry insights. Whether you are a beginner or looking to advance your Office Application skills, The Knowledge Academy's diverse courses and informative blogs have got you covered.
 

Upcoming Programming & DevOps Resources Batches & Dates

Get A Quote

WHO WILL BE FUNDING THE COURSE?

cross

BIGGEST HALLOWEEN
SALE!

GET THE 40% EXTRA OFF!

red-starWHO WILL BE FUNDING THE COURSE?

close

close

Thank you for your enquiry!

One of our training experts will be in touch shortly to go over your training requirements.

close

close

Press esc to close

close close

Back to course information

Thank you for your enquiry!

One of our training experts will be in touch shortly to go overy your training requirements.

close close

Thank you for your enquiry!

One of our training experts will be in touch shortly to go over your training requirements.