Question

Difficulty: Very hardOrder of Execution and Automation Considerations

An enterprise organization maintains automation on the custom object Service_Contract__c. The object has the following active components:
- A Before-Save Record-Triggered Flow that fires on record updates: when Tier__c is set to "Enterprise", it automatically updates Priority__c to "High".
- A custom Validation Rule: formula AND(TEXT(Tier__c) = "Enterprise", TEXT(Priority__c) = "Low") with the error message "Enterprise contracts cannot have Low priority."
- An After-Save Record-Triggered Flow: fires when Priority__c is updated to "High" to create a follow-up Task for the record owner.

A user edits an existing Service_Contract__c record, changing Tier__c from "Standard" to "Enterprise" while leaving Priority__c as "Low", and clicks Save.

What is the expected outcome of this save operation?

  1. The record saves successfully, Priority__c is updated to "High", the validation rule passes, and the follow-up Task is created.Answer
  2. B
    The save operation fails immediately because custom validation rules evaluate user inputs before any record-triggered flows execute.
  3. C
    The record saves successfully with Priority__c as "High", but the After-Save Record-Triggered Flow is bypassed because field changes originated from automated flow logic.
  4. D
    The validation rule triggers an error because validation formulas evaluate original database values before before-save flows commit changes to memory.

Answer

The record saves successfully, Priority__c is updated to "High", the custom validation rule passes, and the follow-up Task is created by the after-save flow.
In the Salesforce Order of Execution, Before-Save Record-Triggered Flows execute prior to custom validation rules. When the user saves the record, the before-save flow immediately updates Priority__c to "High". Subsequently, when custom validation rules are evaluated, the formula checks the updated in-memory values. Because Priority__c is now "High", the validation formula evaluates to FALSE and no error is raised. The record saves successfully and proceeds to after-save processing, triggering the task creation.

Step-by-Step Solution

1
Evaluate initial save steps in the Salesforce Order of Execution
The system initializes the save and runs system-level validation checks.
Basic field formats and required system fields are checked first.
2
Execute Before-Save Record-Triggered Flows
The flow evaluates Tier__c = "Enterprise" and updates the in-memory record field Priority__c to "High".
Before-save flows execute before Apex before-triggers and before custom validation rules.
3
Evaluate Custom Validation Rules
The validation rule formula AND(TEXT(Tier__c) = "Enterprise", TEXT(Priority__c) = "Low") evaluates to FALSE because Priority__c is now "High".
Custom validation rules evaluate the in-memory state of the record, which includes modifications made by before-save flows.
4
Execute After-Save Record-Triggered Flows
The after-save flow detects that Priority__c changed to "High" and successfully creates the follow-up Task.
After saving to the database (before commit), after-save flows and Apex after-triggers execute.

Key Concept

Salesforce Order of Execution sequence between Before-Save Record-Triggered Flows and Custom Validation Rules
Rate this question