Sub topic 2
Before-Save and After-Save Record-Triggered Flows
Assume you know Salesforce objects, fields, related records, Flow Builder elements, formulas, and database transactions.
Before-save flows: updating the triggering record
A before-save flow runs before Salesforce saves the record that started the flow. In Flow Builder, choose Fast Field Updates. Use an Assignment element to change fields through $Record. Salesforce saves those changes with the original record, so no Update Records element or extra database operation is needed.
For example, set the next step for large Opportunities:
AND(
ISNEW(),
{!$Record.Amount} > 100000
)Then configure an Assignment:
Variable: {!$Record.NextStep}
Operator: Equals
Value: Review large dealBefore-save flows are efficient for copying values, calculating fields, and applying simple defaults. They cannot create related records or call actions that require the record to be saved first.
After-save flows: related records and actions
An after-save flow runs after Salesforce saves the triggering record. Choose Actions and Related Records. The flow can create or update related records, send notifications, call actions, and use the saved record's ID.
For example, when an Opportunity becomes Closed Won, create a follow-up Task that uses $Record.Id in WhatId. The record ID is available because the save has completed.
Choosing between before-save and after-save
Use before-save when all changes apply to the triggering record and can happen during the save. It usually performs better because it avoids an additional update operation.
Use after-save when you need the record's ID, related records, notifications, subflows, or external actions. Be aware that updates made by an after-save flow can start another automation transaction. Configure entry conditions carefully to avoid unwanted repeats.
| Requirement | Recommended flow |
|---|---|
| Set `NextStep` on the same Opportunity | Before-save |
| Create a Task related to the Opportunity | After-save |
Exercise
An Opportunity flow must set a field on the Opportunity and create a related Task. Which optimization should handle each operation?
Show answer
Use a before-save flow for the field update and an after-save flow for the Task.