Sub topic 7
Choosing before-save or after-save
This chapter assumes you can build a basic record-triggered flow, you know what a Workflow Rule field update and a Process Builder "Update Records" action do, and you have a sandbox to try the examples in. Every record-triggered flow is either before-save or after-save, so each Workflow Rule or process you migrate needs this choice made for it.
The two flow types
You pick the type when you create the flow. In Flow Builder it is the "Optimize the Flow for" setting.
- Fast Field Updates creates a before-save flow. It runs before the record is written to the database.
- Actions and Related Records creates an after-save flow. It runs after the record is saved, so the record has an Id and can be referenced by other records.
A before-save flow changes the triggering record by assigning values to {!$Record}. No Update Records element is needed, and the platform includes your changes in the save that is already happening. Salesforce documents these flows as much faster than equivalent after-save automation, because they cost no extra save and no extra trigger cycle.
An after-save flow can do everything a before-save flow cannot: create or update other records, send email, call Apex actions, call subflows, and run scheduled or asynchronous paths. The cost is that the triggering record is read-only in the flow. To change it, you need an Update Records element, which causes a second save.
What each type can and cannot do
| Requirement | Before-save | After-save |
|---|---|---|
| Set fields on the triggering record | Yes, by assignment | Yes, but needs an Update Records element and a second save |
| Update related or child records | No | Yes |
| Create records | No | Yes |
| Send email or post to Chatter | No | Yes |
| Call Apex or invocable actions | No | Yes |
| Use scheduled paths | No | Yes |
| Use `{!$Record.Id}` on create | No, the Id does not exist yet | Yes |
| Fires extra triggers and flows on its own field changes | No | Yes, because of the second save |
The last row matters most for performance and recursion. A before-save change is part of the original save, so it does not start another round of triggers. An after-save update to the same record does.
Mapping legacy automation to a flow type
Start from what the old automation did, not from how it was built.
| Legacy automation | Flow type |
|---|---|
| Workflow field update on the same record | Before-save |
| Process Builder "Update Records" on the triggering record | Before-save |
| Update Records on a parent or child record | After-save |
| Email alert | After-save |
| Create a Task or another record | After-save |
| Invoke Apex or a flow from a process | After-save |
| Time-dependent action or scheduled action | After-save, with a scheduled path |
If one Workflow Rule or process does several of these things, split the work across two flows. One before-save flow handles the same-record field updates. One after-save flow handles the rest. Both use the same entry conditions, which you translate in the next chapter.
A decision path
The second question catches cases that look like simple field updates. If the value depends on {!$Record.Id} on create, a before-save flow cannot work, because the Id does not exist yet. If the update must wait until a future date, it needs a scheduled path.
Worked example: field update
A Workflow Rule sets Priority__c to "High" on Cases when Amount__c is over 10,000. The Workflow Rule formula and the equivalent flow logic look like this:
Workflow Rule criteria:
Amount__c > 10000
Before-save flow, Optimize for Fast Field Updates:
Start: Case, A record is created or updated
Entry condition (Formula Evaluates to True): {!$Record.Amount__c} > 10000
Assignment element:
{!$Record.Priority__c} Equals HighThere is no Update Records element. The Assignment writes straight to the record that is about to be saved. If you add an Update Records element to a before-save flow, Flow Builder will not let you.
Worked example: mixed requirements
A process does three things when an Opportunity is Closed Won: it sets Won_Date__c, creates a follow-up Task, and updates the parent Account's Last_Win__c. Build two flows on Opportunity:
- A before-save flow assigns
{!$Record.Won_Date__c}fromTODAY(). - An after-save flow creates the Task with
WhatId = {!$Record.Id}. It also updates the Account through a Get Records and Update Records pair, or an Update Records element that targets the related record.
Keep the entry conditions identical, or tighter on the after-save flow if the Task should only be created once.
Checking what you have built
After the migration, list the active record-triggered flows and their types. Run this with the Tooling API option checked. It also shows you whether anything still depends on after-save updates that a before-save flow could replace.
SELECT ApiName, Label, TriggerType, IsActive
FROM FlowDefinitionView
WHERE ProcessType = 'AutoLaunchedFlow' AND IsActive = trueTriggerType shows RecordBeforeSave or RecordAfterSave for record-triggered flows.
Edge cases and common errors
- Using after-save for everything. This works, because after-save can do all the actions. It is slower, and every Update Records on the triggering record causes another save. Use before-save for same-record field updates.
- Expecting an Id on create in a before-save flow.
{!$Record.Id}is blank. Move that logic to an after-save flow. - Updating the triggering record in an after-save flow. The second save runs triggers and record-triggered flows again. If the entry condition is still true, the flow can run a second time. Set the run frequency to "Only when a record is updated to meet the condition requirements", or add a condition that is false after your update.
- Trying to update a related record from a before-save flow. Flow Builder does not offer the element. Use an after-save flow.
- Assuming a flow's type can be switched freely. You choose it at creation, so decide before you build. If you chose wrong, rebuild the flow as the other type instead of working around it.
- Changing a formula field. Formula fields are read-only in both flow types. Assign to the underlying fields instead.
Summary of the decision
Choose before-save when the only job is setting fields on the triggering record, and the values do not depend on the record's Id. Choose after-save for anything else. If the old automation does both, build both flows.
Exercise
A process on Account sets Rating to "Hot" when AnnualRevenue exceeds 5,000,000, and also sends an email alert to the account owner in the same criteria node. Which flow type or types should replace it, and why?
Show answer
Use two flows on Account with the same entry condition. A before-save flow assigns {!$Record.Rating} to "Hot", because that is a same-record field update. An after-save flow sends the email, because before-save flows cannot send email or call actions.
Exercise
A Workflow Rule creates a Task related to the new Opportunity as soon as the Opportunity is created. Why can't a before-save flow do this, and what flow type is needed?
Show answer
A before-save flow cannot create records, and on create the Opportunity has no Id yet to use as the Task's WhatId. An after-save flow can create the Task and use {!$Record.Id}.