Sub topic 1
What a Record-Triggered Flow Is and When It Runs
A record-triggered flow is an automation that starts by itself when a record is created, updated, or deleted. You don't launch it from a button or a screen. Salesforce launches it as part of saving data. This chapter covers what starts a flow, what the two optimizations are, and how a flow fits into a save operation.
Prerequisites
This chapter assumes you already know the following:
- The basic Salesforce data model: objects, fields, and related records.
- Flow Builder and its main elements: Assignment, Decision, Get Records, Create Records, and Update Records.
- Basic formulas and Boolean logic.
- What a database transaction is: a group of changes that all succeed or all roll back together.
What starts a record-triggered flow
A record-triggered flow is tied to one object and one trigger event. When a matching record change happens, Salesforce checks the flow's entry conditions. If the record passes, the flow runs with that record as its input.
The supported trigger events are:
- A record is created.
- A record is updated.
- A record is created or updated.
- A record is deleted.
The change can come from the UI, an API call, a data import, Apex code, or another automation. The flow does not care about the source. Anything that saves the record can start it.
The two optimizations
When you create the flow, Flow Builder asks what to optimize for. This choice sets how and when the flow runs.
| Optimization | Also called | Runs | Typical use |
|---|---|---|---|
| Fast Field Updates | Before-save | Before the record is written to the database | Change fields on the triggering record |
| Actions and Related Records | After-save | After the record is written, still inside the transaction | Create or update other records, send emails, call actions |
A before-save flow edits the triggering record in memory. Salesforce then saves those edits along with the original change, so no extra DML (a database write operation) is needed. An after-save flow runs once the record exists. The record now has an Id, so you can relate other records to it.
Later chapters compare the two in detail. For now, remember the split: before-save changes the record itself, and after-save does everything else.
A first example
Here is a before-save flow. It sets a field on a large Opportunity without any Update Records element.
Flow: Opportunity - Set Next Step (before-save)
Object: Opportunity
Trigger: A record is created or updated
Optimize for: Fast Field Updates
Entry condition: {!$Record.Amount} > 100000
Run: Only when a record is updated to meet the condition requirements
Assignment element
Variable: {!$Record.NextStep}
Operator: Equals
Value: Review large dealThe flow reads {!$Record}, which holds the values of the record being saved. It assigns a value to NextStep. Salesforce writes that value in the same save.
Where a flow sits in a save
A flow is one step in a larger sequence. A save also runs validation, Apex triggers, and other automation. Everything happens in one transaction, which means the flow shares governor limits (per-transaction caps on queries, DML, and CPU time) with Apex and other automation in that transaction.
This is a simplified view. The full order of execution has more steps and is covered in a later chapter.
Common mistakes
- Choosing "created or updated" when you only need "created". The flow then evaluates on every edit.
- Expecting a before-save flow to create related records. It can't, because the record has no
Idyet on create. - Forgetting that an error in an after-save flow rolls back the whole transaction, including the original record change.
Exercise
A flow must set a field on the Opportunity being saved, and it must not use an extra DML operation. Which optimization do you choose, and why?
Show answer
Fast Field Updates (before-save). It changes the triggering record in memory before it is written, so Salesforce saves the change with the original operation and no Update Records element is required.
Exercise
You need to create a Task related to an Opportunity when it is created. Why can't a before-save flow do this?
Show answer
On create, the record has no Id before it is saved, so a Task cannot reference it. An after-save flow runs once the record is written and has an Id, so use Actions and Related Records.