Sub topic 6
Record-triggered flows: the replacement for both tools
This chapter assumes you can open Flow Builder in a sandbox or Developer Edition org. It also assumes you know how a Workflow Rule's evaluation criteria work, or how a Process Builder process is started. You should be able to read a basic formula. Later chapters cover the details of mapping criteria and actions. This one gives you the model that both tools map onto.
One tool for two jobs
Workflow Rules and Process Builder both react to a record being saved. A record-triggered flow does the same thing. Each one is a flow that starts when a record of one object is created, updated, or deleted.
You create one in Setup under Flows. Choose New Flow, then Record-Triggered Flow. The Start element holds four settings. Together they replace the rule or process header you already know.
| Start setting | What it controls | Closest old concept |
|---|---|---|
| Object | The one object whose saves start the flow | Object on the rule or process |
| Trigger the flow when | Created, updated, created or updated, or deleted | Evaluation criteria |
| Entry conditions | Which records qualify | Rule criteria or process criteria node |
| Optimize the flow for | Fast Field Updates (before-save) or Actions and Related Records (after-save) | No equivalent. The old tools were always after-save. |
A flow belongs to exactly one object and one trigger type. If a Process Builder process covered Account on create and edit, expect to build a flow that covers both, or split it into more than one flow. Chapter order of execution and consolidation later in this tutorial explain how to choose.
What happens when a record saves
A flow does not run at an arbitrary moment. It is tied to a specific point in the save. The flow first checks whether the change matches its trigger. Then it checks entry conditions. Then it applies the run-frequency rule. Only then do its elements execute.
Each of the three checks can stop the flow. When a migrated flow fires too often or never fires, look at these three gates in order.
Triggers and run frequency
For an updated record, the Start element asks how often the flow should run. This is the setting that replaces the evaluation criteria in a Workflow Rule and the "only when specified changes are made" option in Process Builder.
- Every time a record is updated and meets the condition requirements. The flow runs on each save where the record meets the entry conditions, even if nothing relevant changed.
- Only when a record is updated to meet the condition requirements. The flow runs when the record did not meet the conditions before the save and does meet them after it. Salesforce compares the record to its prior values.
The mapping from Workflow evaluation criteria is direct:
- "Created" maps to the trigger A record is created.
- "Created, and every time it's edited" maps to created or updated, with every time.
- "Created, and any time it's edited to subsequently meet criteria" maps to created or updated, with only when updated to meet the condition requirements.
Entry conditions
Entry conditions decide which records start the flow. Using them is better than starting the flow for every record and filtering with a Decision element. A record that fails the entry conditions never starts the flow, so it costs almost nothing.
You can choose All Conditions Are Met (AND), Any Condition Is Met (OR), Custom Condition Logic, or Formula Evaluates to True. Use a formula when a Workflow Rule used a formula, or when you need $Record__Prior:
AND(
TEXT({!$Record.StageName}) = "Closed Won",
{!$Record.Amount} > 100000
)Note the TEXT() call. A picklist in a flow formula is read with TEXT(), where a Workflow formula used ISPICKVAL(). Compare to the previous value with {!$Record__Prior.StageName}. The prior record exists only in update-triggered flows, so a flow that triggers on create alone cannot use it.
Before-save and after-save
The Optimize the flow for choice sets when the flow runs relative to the database write.
- Fast Field Updates runs before the record is saved. It can change fields on the triggering record only, with an Assignment or Update Records element that targets
$Record. It cannot create other records, send email, or call actions. Because it needs no extra database write, it is the fastest option. - Actions and Related Records runs after the record is saved. It can create and update other records, send email, call subflows and invocable Apex, and post to Chatter. Updating the triggering record itself costs an extra save.
Neither Workflow nor Process Builder offered a before-save mode. Most simple field updates on the same record, which both tools handled with an after-save write, can move to a before-save flow. The next chapter covers how to decide.
Scheduled paths and asynchronous paths
An after-save flow can have more than one path leaving the Start element:
- The Run Immediately path executes with the save.
- A Scheduled Path runs at a time you define, relative to a date field on the record or to the trigger time. This replaces Workflow time-dependent actions and Process Builder scheduled actions.
- A Run Asynchronously path runs after the save transaction completes. Use it for work such as callouts that should not hold up the user's save.
Scheduled paths belong only to after-save flows. A before-save flow has a single path.
Delete triggers
Both old tools ignored deletes. Flows can run when a record is deleted. A flow that runs before delete can block the delete or collect data from the record. A flow that runs after delete can clean up related data. These flows have no equivalent in your existing automation, so they will not appear in a migration. Treat them as a new capability, not as part of the cutover.
Finding record-triggered flows in an org
After you start building, you need to tell flows apart. This query lists active flows with their trigger type:
SELECT ApiName, Label, ProcessType, TriggerType, IsActive
FROM FlowDefinitionView
WHERE IsActive = true AND TriggerType IN ('RecordBeforeSave', 'RecordAfterSave')Record-triggered flows report TriggerType as RecordBeforeSave or RecordAfterSave. Their process type is AutolaunchedFlow. Old Process Builder processes also appear in FlowDefinitionView, with the process type Workflow, so always filter on both fields.
Common errors
- Choosing the wrong trigger. A flow set to "created" never reruns on edit. If the old rule ran on edit, the flow silently skips it.
- Using
ISPICKVALin a flow formula. It is not a valid flow function. UseTEXT(). - Updating the triggering record in an after-save flow. This causes another save, which can start flows again. The chapter on bulk safety and recursion covers the controls.
- Expecting a before-save flow to create a Task. It cannot. Switch to after-save.
- Leaving the old rule active. If both the rule and the new flow remain active, both fire. Deactivate the old automation only as part of your cutover plan.
Exercise
A Workflow Rule on Opportunity has the evaluation criteria "created, and any time it's edited to subsequently meet criteria." Its rule criteria are ISPICKVAL(StageName, "Closed Won"). It creates a follow-up Task. Describe the Start element settings for the replacement flow, including the optimization mode.
Show answer
Object: Opportunity. Trigger: A record is created or updated. Entry condition: a formula such as TEXT({!$Record.StageName}) = "Closed Won" (or a condition StageName Equals Closed Won). Run frequency: Only when a record is updated to meet the condition requirements. Optimize for: Actions and Related Records (after-save), because creating a Task is a change to another record and a before-save flow cannot do it.