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 seen the tools covered earlier: validation rules, formulas, Flow, approval processes, and Apex. The goal is a repeatable way to pick one tool for a requirement.
The checklist
Work from the simplest tool to the most complex. Stop at the first step that fits.
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.Applying it
Take the requirement "set an account's Rating to Hot when AnnualRevenue is at least 1,000,000." It changes the record being saved, so a before-save record-triggered flow is enough. The same logic as an Apex trigger looks 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';
}
}
}The trigger works and is bulk-safe, but it needs tests, deployment, and a developer to maintain it. Choose it only if a flow cannot express the logic.
Now suppose you must recalculate ratings for hundreds of thousands of accounts. That volume can strain a flow and a single transaction. Move the work to Queueable Apex, which runs in its own transaction with its own limits:
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));Criteria beyond the checklist
| Question | Leans toward |
|---|---|
| Who will maintain it? | Flow if admins own it, Apex if developers do |
| Is the logic complex or heavily reused? | Apex |
| Does it already have automation on the object? | Extend the existing tool to avoid conflicts |
| Is it legacy Workflow or Process Builder? | Migrate to Flow |
Common errors
- Starting with Apex because it feels more powerful.
- Mixing a flow and a trigger on the same object and event without checking the order of execution.
- Choosing by volume guesses instead of limits you have measured.
- Skipping a plan for testing and monitoring.
Exercise
A sales manager wants each new Opportunity over $500,000 to need director approval, and the Opportunity's Priority field should be set to High on save. Which tools do you pick, and in what order did you reach them?
Show answer
Use an approval process for the director sign-off (step 5, formal sign-off). Use a before-save record-triggered flow to set Priority to High (step 2, changing the record being saved). Neither needs Apex, so you stop before step 6.