Sub topic 17
When to Use Which Flow Type, and When Not To
This chapter assumes you have built at least one autolaunched flow and one schedule-triggered flow. It also assumes you know what a Subflow is and how governor limits constrain a transaction. Here you choose among the options, including options that are not flows.
Start with the trigger, not the tool
Every automation starts from one of four events:
- Someone does something on a screen.
- A record is created, updated, or deleted.
- Time passes.
- Another piece of automation asks for the work.
Match the event to the flow type first. Then check volume, complexity, and who maintains it.
| Need | Best fit | Why |
|---|---|---|
| A user answers questions and the flow acts on the answers | Screen flow | It is the only type with UI elements. |
| React when a record changes | Record-triggered flow | It runs in the same transaction and can use before-save updates. |
| Act relative to a record's date field (7 days after Close Date) | Record-triggered flow with a scheduled path | The platform schedules the work from the record's own data. |
| Process a set of records at a fixed time | Schedule-triggered flow | It selects records by filter and runs daily, weekly, or once. |
| Shared logic called by several callers | Autolaunched flow | It has no trigger and takes input and output variables. |
| Heavy or complex batch work | Scheduled or Batch Apex | It offers larger batches, custom queries, and finer control. |
When a schedule-triggered flow is the right choice
Use a schedule-triggered flow when all of these are true:
- The work is periodic and does not depend on a user or a record event.
- You can express the target records as filter conditions on one object.
- The per-record logic fits in declarative elements.
- The schedule is once, daily, or weekly.
Typical examples are closing stale cases nightly, sending a weekly digest, or flagging opportunities that sit in Prospecting for too long.
Each selected record becomes its own flow interview, and the platform processes interviews in batches. Design the flow for one record at a time and let the platform handle the volume. Your record filters are the main way to control cost.
Scheduled flows have platform limits on how many interviews can run in 24 hours. Check the current limit in Salesforce's documentation, because it depends on edition and licenses.
Signs a scheduled flow is the wrong tool
- You need to run more often than daily. The scheduler offers no hourly option.
- The selection needs a join, an aggregate, or a subquery that a single-object filter cannot express.
- You must control batch size, chain jobs, or process millions of rows.
- You need guaranteed ordering, or a retry strategy more specific than a fault path.
When an autolaunched flow is the right choice
An autolaunched flow does not start itself. Choose it when the logic is shared or when another caller needs to run it. Examples:
- Several record-triggered flows need the same "assign owner by territory" logic. Put it in one autolaunched flow and call it with Subflow.
- Apex or an external system must run declarative logic that admins maintain.
- A scheduled flow's per-record work is large enough to deserve its own tested unit.
Keep the contract small. Define input variables for what the caller must supply and output variables for what it needs back. Mark nothing as available for input or output unless a caller uses it.
Signs an autolaunched flow is the wrong tool
- Only one flow would ever call it. A subflow then adds an indirection and a second version to manage, with no reuse gain.
- The logic needs the triggering record's before-save context. A subflow cannot give you the fast before-save behavior of the parent.
- The caller needs a synchronous answer from a long-running operation. Flow has no mechanism to wait on external work.
Flow or Apex
Declarative first is a sound default, but it is not a rule. The following table summarizes the trade-offs.
| Criterion | Flow | Apex |
|---|---|---|
| Who can change it | Admins | Developers with a deployment process |
| Testing | Debug runs, flow tests for record-triggered flows | Unit tests are required for deployment and give assertions |
| Batch control | Platform decides | You set batch size and chaining |
| Complex logic | Becomes hard to read quickly | Easier to structure and reuse |
| Frequency | Once, daily, weekly | Cron expressions, or chained jobs |
A common hybrid is to keep the business rules in an autolaunched flow and use a small Apex scheduler to call it. That gives you cron-level timing with admin-maintained logic.
The Apex below is a complete scheduled batch job. It is a reasonable replacement when a schedule-triggered flow would hit volume limits.
public class StaleCaseBatch implements Database.Batchable<SObject>, Schedulable {
public Database.QueryLocator start(Database.BatchableContext bc) {
return Database.getQueryLocator([
SELECT Id FROM Case
WHERE Status = 'New' AND LastModifiedDate < LAST_N_DAYS:30
]);
}
public void execute(Database.BatchableContext bc, List<Case> scope) {
for (Case c : scope) {
c.Status = 'Closed';
}
update scope;
}
public void finish(Database.BatchableContext bc) {}
public void execute(SchedulableContext sc) {
Database.executeBatch(new StaleCaseBatch(), 200);
}
}Run this once in Anonymous Apex to schedule it for 02:00 every day:
System.schedule('Stale cases nightly', '0 0 2 * * ?', new StaleCaseBatch());Common mistakes
- Using a scheduled flow to poll. Checking every day for a change that a record-triggered flow could catch immediately wastes interviews and adds up to a day of delay.
- Using a scheduled flow for date-relative work. "Seven days after Close Date" is a scheduled path on a record-triggered flow. A daily scheduled flow with a date filter works, but it re-evaluates every record each day.
- Putting every rule in one giant flow. Split by responsibility. Use autolaunched flows for the parts that more than one caller needs.
- Forgetting the run context. A scheduled flow runs without a user, so it needs access to everything it touches. Test with the same permissions it will have in production.
- Skipping fault paths because the flow is "just a nightly job". Nobody watches a nightly job. Without a fault path, you learn about failures from a user complaint.
Quick checklist
- Name the event that starts the work.
- Check that the frequency fits the platform's scheduler.
- Estimate record volume per run.
- Decide whether more than one caller needs the logic.
- Decide who will maintain it: admins or developers.
- Plan the fault path and who is notified.
Exercise
Your team wants to email the account owner 14 days after each Opportunity's Close Date passes without a Closed Won stage. Another request is to recalculate a health score for every Account each night, using a SOQL aggregate across child records. Which tool fits each request, and why?
Show answer
Use a record-triggered flow with a scheduled path for the first request. The delay is relative to a date field on each record, so the platform schedules each record's action itself. Use scheduled Batch Apex for the second request. A schedule-triggered flow filters one object and cannot express the aggregate, and the volume across all accounts is better handled by controlling batch size in Apex. An autolaunched flow could still hold shared logic, but it would need an Apex or flow caller to start it.
Exercise
Name two signs that a planned autolaunched flow should not exist as a separate flow.
Show answer
Only one flow would ever call it, so the subflow adds a second version to manage without any reuse. Or the logic depends on the before-save context of the triggering record, which a subflow cannot provide.