Sub topic 17
A decision framework for choosing the right tool
This chapter assumes you know the Salesforce data model, can navigate Setup and the Object Manager, and have read the earlier chapters on Flow types, approval processes, Apex triggers, governor limits, and the order of execution. Here you combine those parts into one repeatable way to pick a tool.
Why a framework helps
Most requirements can be built in more than one way. A field update after a save can be done by a before-save flow, an after-save flow, an Apex trigger, or a legacy Workflow Rule. If each builder picks by habit, one object ends up with a mix of tools that run in a fixed order and can overwrite each other.
A framework replaces habit with a fixed sequence of questions. You ask them from the simplest tool to the most complex, and you stop at the first tool that fully meets the requirement. This is the clicks-before-code principle turned into a checklist.
The ordered questions
1. Can a validation rule, formula field or roll-up summary field solve it? Use that.
2. Does it run when a record is created or updated? Try a record-triggered flow (before-save to change the same record, after-save for related records or actions).
3. Does a user need guided steps? Use a screen flow.
4. Does it run on a schedule? Use a scheduled flow, or scheduled Apex for very large volumes.
5. Does it need formal sign-off? Use an approval process, or Flow Orchestrator for multi-step work across users.
6. Does it need complex logic, very large volumes, or something Flow cannot do? Use Apex, and move slow work to asynchronous Apex.The order is a priority list. It is not a routing table. A requirement can match question 2 and still fail on a limit, in which case you continue down the list.
Working through the questions
Question 1: declarative features
Use a validation rule to block bad data, a formula field to display a value computed from the same record or a parent, and a roll-up summary field to aggregate child records on a master-detail relationship. These need no maintenance logic and cannot fail at runtime in the way a flow can. If the value does not need to be stored or edited, prefer a formula field to automation that writes the value.
Question 2: record-triggered flow
Choose before-save when you only change fields on the record being saved. It needs no DML statement and is the fastest option. Choose after-save when you must create or update related records, send email, post to Chatter, or call an action. Putting a same-record update in an after-save flow works, but it costs an extra save and re-runs other automation.
Questions 3 to 5: other triggers for the work
- A screen flow is started by a user, from a button, a quick action, or a Lightning page. Nothing else starts it.
- A scheduled flow runs at a set time against records that match filter criteria. It suits nightly cleanup and reminders.
- An approval process records who approved, when, and what happened on rejection. Use it when the audit trail of sign-off is the point. Use Flow Orchestrator when several steps and several people are involved, and each step may wait on the one before.
Question 6: Apex
Apex is justified when Flow cannot express the logic or cannot meet volume or performance needs. The same trigger that sets a rating can be written like this:
trigger AccountTrigger on Account (before insert, before update) {
for (Account acc : Trigger.new) {
if (acc.AnnualRevenue != null && acc.AnnualRevenue >= 1000000) {
acc.Rating = 'Hot';
}
}
}This requirement fails question 1, and it is a same-record change on save, so a before-save flow does the same job without code. The trigger is correct and bulk-safe, but it fails the framework because a simpler tool fits. It would be justified only if, for example, the rule depended on logic Flow could not express.
When work is slow or large, move it out of the save transaction:
public class RecalculateRatingJob implements Queueable {
private List<Id> accountIds;
public RecalculateRatingJob(List<Id> accountIds) {
this.accountIds = accountIds;
}
public void execute(QueueableContext context) {
List<Account> accounts = [SELECT Id, AnnualRevenue FROM Account WHERE Id IN :accountIds];
for (Account acc : accounts) {
acc.Rating = (acc.AnnualRevenue != null && acc.AnnualRevenue >= 1000000) ? 'Hot' : 'Warm';
}
update accounts;
}
}
// Enqueue from Apex, for example inside a trigger handler:
// System.enqueueJob(new RecalculateRatingJob(accountIdList));The job runs in its own transaction with its own governor limits, and it uses one query and one DML statement for the whole list.
Checks that go beyond fit
Passing the question list tells you a tool can do the job. Check these before you commit.
| Check | What to ask | Effect on the choice |
|---|---|---|
| Volume | How many records per transaction and per day? | High volume pushes toward Apex or scheduled Apex. |
| Existing automation | What already runs on this object? | Prefer extending the current tool over adding a second one. |
| Order of execution | Does your step run before or after the others? | Decides before-save versus after-save, and exposes recursion. |
| Ownership | Who will maintain this in a year? | Admin-maintained work favors Flow. Code needs developers and tests. |
| Legacy status | Is the current rule a Workflow Rule or Process Builder process? | Salesforce has ended support for both, so build new work in Flow and plan migration. |
Common errors
- Starting with Apex because it feels more powerful. The result is code that an admin cannot change and that needs deployment for every edit.
- Building several record-triggered flows on one object for the same event with no ordering. Prefer one flow per object and event, or set the trigger order explicitly.
- Using a flow where a roll-up summary field would do. The flow adds failure points and a maintenance cost.
- Ignoring bulk behavior. A flow that works for one record can still hit limits during a data load of 200 or more records.
- Mixing a flow and a trigger that both update the same field. The later step in the order of execution silently wins.
Recording the decision
For each requirement, write down the tool you chose, the question that selected it, and the question that ruled out the simpler options. Place this in the flow description or Apex class header. A later maintainer can then see why the requirement is built the way it is, and can revisit it if limits or platform support change.
Exercise
A sales manager wants every Opportunity to set its Next Review Date to 30 days after Close Date whenever either value is saved. No other records are affected. Which tool do you pick, and which question in the framework selects it?
Show answer
A before-save record-triggered flow. A formula field would be the first choice if the date only needs to be displayed, and it would be selected by question 1. Because the value must be stored and edited, question 1 is not enough. Question 2 then applies: the work runs on save and changes only the same record, so a before-save flow fits. It needs no DML statement and no Apex.
Exercise
A requirement says that when a Case is closed, you must create follow-up Tasks, call an external system whose response takes several seconds, and update 5,000 related records. Name the tools you would consider and explain why one alone may not be enough.
Show answer
An after-save record-triggered flow handles the Tasks and related updates, since after-save work can touch other records. The slow external call and the large update are better moved to asynchronous Apex, such as a Queueable class, so they run in their own transaction with their own limits. Question 2 gets you the first part, and question 6 handles the parts that exceed what the save transaction should carry.