Sub topic 1
What a Record-Triggered Flow Is and When It Runs
A record-triggered flow is an automation that Salesforce starts by itself when a record is created, updated, or deleted. You don't launch it from a button, a screen, or a schedule. A data change launches it. This chapter explains what starts a flow, which events it can react to, and where in a save it runs. Later chapters cover each part in detail.
Prerequisites
This chapter assumes you know the following:
- The Salesforce data model: objects, fields, and related records.
- Flow Builder and its main elements: Assignment, Decision, Get Records, Create Records, and Update Records.
- Formulas and Boolean logic (AND, OR, NOT, comparisons).
- What a database transaction is: a group of changes that all succeed or all roll back together.
The core idea
A record-triggered flow is attached to one object and one trigger event. Whenever a matching change happens to a record of that object, Salesforce starts a new interview of the flow. An interview is one run of a flow. The triggering record is available inside the flow as {!$Record}.
Some practical consequences follow:
- The flow runs no matter how the change was made. A user editing a page layout, a data import, an API call, and Apex DML (Data Manipulation Language, such as
insertandupdatestatements) can all start it. - The flow runs inside the same transaction as the save. If the transaction fails, the flow's changes roll back with it.
- A flow runs in system context. The running user's field-level security and sharing do not limit what the flow can read or write. Design it with that in mind.
- Salesforce runs the flow for every record in the save, not only the first one. A data load of 200 records produces 200 interviews, handled in bulk.
Trigger events
When you create a record-triggered flow, you choose the object and then one of four trigger events.
| Trigger event | Starts when | Typical use |
|---|---|---|
| A record is created | A new record is inserted | Set defaults, create a welcome Task |
| A record is updated | An existing record is saved with changes | React to a stage change |
| A record is created or updated | Either of the two above happens | One flow that covers both cases |
| A record is deleted | A record is deleted | Block a delete, clean up related data |
"Updated" is worth a closer look. A save that changes no field values still counts as an update for most purposes, so a flow with no entry condition can run on saves that changed nothing. You normally prevent that with entry conditions, which the next chapters cover.
Choose "created or updated" only when the logic really is the same for both events. If creation and update need different behavior, two flows (or one flow with a Decision element) are clearer than one flow full of special cases.
Two points in the save: before and after
Every record-triggered flow is optimized for one of two moments in the save. You choose this in the Optimize the Flow for setting.
- Fast Field Updates is the before-save type. The flow runs before the record is written to the database. It can change fields on the triggering record directly, with no extra DML.
- Actions and Related Records is the after-save type. The flow runs after the record is written, so
{!$Record.Id}exists even for a new record. It can create or update other records, send emails, and call actions.
Here is a simplified view of one save.
This is a simplification. The real order of execution includes Apex triggers, duplicate rules, workflow rules, and more. A later chapter covers it. For now, remember two facts. A before-save flow runs before the record is saved. An after-save flow runs after the record is saved but before the transaction commits.
Delete flows follow the same idea. They can run before the record is deleted or after it is deleted. Before-delete logic is useful when you need to inspect the record or stop the delete.
A first look at an entry condition
Without conditions, a flow starts for every matching change to the object. An entry condition limits the flow to the records you care about. You set the conditions in the Start element.
You can define the condition with filter rows, or with the Formula Evaluates to True option. This formula starts the flow only when an Opportunity's stage has just changed to Closed Won:
AND(
ISCHANGED({!$Record.StageName}),
{!$Record.StageName} = "Closed Won"
)ISCHANGED compares the current value with the value before the save. That value is also available as {!$Record__Prior}, a later topic.
The Start element also has a run frequency setting for update flows:
- Only when a record is updated to meet the condition requirements: the flow runs when the record goes from not meeting the conditions to meeting them.
- Every time a record is updated and meets the condition requirements: the flow runs on every matching update, even if the record already met the conditions.
The first setting is the safer default. It stops a flow from firing again on each later save of a record that already qualifies.
What a flow can and cannot do
Each type has limits.
- A before-save flow can only update the triggering record's own fields. It cannot create other records or call most actions. It also cannot update the triggering record through an Update Records element.
- An after-save flow can do much more, but changing the triggering record there needs an Update Records element. That costs an extra DML operation and can fire further automation on the same record.
- Both types share the transaction's governor limits with Apex and other automation. Governor limits are per-transaction caps, for example on the number of SOQL queries or DML statements. A flow is not exempt from them.
A small before-save example shows the difference. This flow sets a field on a large Opportunity with an Assignment 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 dealNo Update Records element appears. Assigning to {!$Record.NextStep} is enough, because Salesforce was about to save the record anyway.
An after-save flow uses the Id that exists once the save completes. This one creates a related Task:
Flow: Opportunity - Create Follow-up Task (after-save)
Object: Opportunity
Trigger: A record is created or updated
Optimize for: Actions and Related Records
Entry condition: {!$Record.StageName} = "Closed Won"
Run: Only when a record is updated to meet the condition requirements
Create Records element (object: Task)
Subject: Send welcome package
WhatId: {!$Record.Id}
OwnerId: {!$Record.OwnerId}Two flows on one object both run. You can have several record-triggered flows on the same object and event, and Salesforce does not guarantee a specific order between them unless you set one. Keep each flow small and focused.
Common mistakes at this stage
- No entry condition. The flow runs on every save of the object. This wastes limits and can cause surprising side effects.
- Using after-save for a simple field change. It works, but the Update Records element adds DML and may re-trigger automation. Use before-save when you only change the triggering record.
- Assuming the user's permissions apply. The flow runs in system context, so it may write fields the user could not edit. Review what it changes.
- Reading
{!$Record.Id}in a before-save create flow. The record has no Id yet, so the value is empty. Use an after-save flow when you need the Id. - Testing with one record. Flows run in bulk. A design that works for one record may hit limits at 200.
Exercise
A flow must set the Description field on a new Case to a default text, and it must also create a related Task for the Case owner. For each requirement, say whether it fits a before-save or an after-save flow, and why.
Show answer
Setting Description on the new Case fits before-save (Fast Field Updates). It changes only the triggering record, so an Assignment to {!$Record.Description} is enough and needs no extra DML. Creating the Task fits after-save (Actions and Related Records). Creating a related record needs the Case's Id, which exists only after the save, and before-save flows cannot create other records.
Exercise
A flow has the trigger "A record is updated" and the entry condition {!$Record.StageName} = "Closed Won". A user edits the Description of an Opportunity that is already Closed Won. With the run frequency "Every time a record is updated and meets the condition requirements," does the flow run? What changes if you pick "Only when a record is updated to meet the condition requirements"?
Show answer
With "Every time," the flow runs, because the record is updated and still meets the condition. With "Only when a record is updated to meet the condition requirements," the flow does not run, because the record already met the condition before the save. It would run only if the stage changed from something else to Closed Won.