Sub topic 7
Choosing before-save or after-save
This chapter assumes you can read a Workflow Rule or Process Builder process, know basic formula syntax, and have a sandbox where you can build a record-triggered flow. Once you know a flow's trigger, you still have to choose how it runs. A record-triggered flow can run before the record is saved to the database or after. That choice decides which actions the flow can perform and how much it costs.
The two timings
A before-save flow runs before Salesforce writes the record. It can only change fields on the record that started the flow. Because it edits the record in memory, it needs no separate DML (database write) operation. Salesforce calls this a fast field update.
An after-save flow runs after the record is written. The record has an Id, and related records can be created or updated. This is the only timing that supports most actions beyond a field update on the triggering record.
| Requirement | Before-save | After-save |
|---|---|---|
| Update fields on the triggering record | Yes, and fastest | Yes, but costs an extra update |
| Update or create related records | No | Yes |
| Send email, post to Chatter, create tasks | No | Yes |
| Call Apex, subflows, or invocable actions | No | Yes |
| Use the new record's Id | No on create | Yes |
| Scheduled paths | No | Yes |
Mapping old tools to the new timing
Workflow field updates map well to before-save. A Workflow Rule that sets Priority__c on the same record is a before-save flow. Process Builder is different. A process that updates its own record and then creates a Task needs after-save for the Task. If you want the speed of before-save for the field update, you can build two flows, though the consolidation chapter explains why that has a cost.
The reverse mistake is common. A migrator sees "Update Records" in Process Builder and places everything in an after-save flow. This works, but an after-save update of the triggering record causes a second save. That save can re-run triggers and other automation.
A decision path
Ask these questions in order.
Common errors
- Choosing after-save by default. This adds unnecessary updates and slows bulk loads.
- Expecting a related-record update in before-save. The element is not available, so the design fails during the build.
- Relying on the Id on insert. A before-save flow on create has no Id yet. A Task that needs
WhatIdmust be created after save. - Splitting needlessly. Two flows for one rule are harder to order and debug. Split only when the performance gain is worth it.
Exercise
A Process Builder process runs when an Opportunity becomes Closed Won. It sets a custom field Won_Date__c on the Opportunity and creates a follow-up Task. Which flow timing or timings do you use?
Show answer
The Task needs the saved Opportunity Id, and creating a record is not allowed in before-save, so you need an after-save flow. You can do the Won_Date__c update in the same after-save flow, at the cost of an extra save. Or you can add a before-save flow for that field update, which is faster but gives you two flows to order and maintain.