Sub topic 7
Scheduled flows for time-based batch work
This chapter assumes you can build a basic flow in Flow Builder and know the difference between record-triggered and screen flows. It covers when a scheduled flow is the right tool and the mistakes people make with it.
What a scheduled flow does
A scheduled flow runs at a set time without any user or record change starting it. You pick a start date, a time, and a frequency of once, daily, or weekly. The flow has no screens, because nobody is present when it runs.
Use it when the trigger is the clock, not a record save. Typical cases:
- Close cases that have had no activity for 30 days.
- Email owners of opportunities whose close date has passed.
- Update a field on thousands of records every night.
How the Start element works
In the Start element you choose an object and filter conditions. Salesforce finds the matching records at run time and starts a separate flow interview for each one. The records are processed in batches, so the flow's elements run against many records together.
If you don't choose an object, the flow runs once per schedule with no record. That fits jobs such as sending a weekly summary.
Choosing it over other tools
| Requirement | Better tool |
|---|---|
| Runs on a schedule, moderate volume | Scheduled flow |
| Runs when a record changes | Record-triggered flow |
| Needs user input | Screen flow |
| Very large volume or complex logic | Scheduled Apex with Batch Apex |
A related option is a record-triggered flow with a scheduled path. It waits a set time after a record event, such as 7 days after creation. Use it when the delay is relative to each record. Use a scheduled flow when everything runs at one fixed time.
Common errors
- Filtering too late. Put your conditions in the Start element. If you fetch all records and filter inside the flow, you waste interviews and risk hitting limits.
- Forgetting activation. An inactive flow never runs, and a scheduled flow can silently do nothing.
- Assuming a user context. The flow runs as the Automated Process user, not a person. Fields like
$Userdon't give you the owner you expect. - Ignoring time zones. The start time uses the time zone of the user who activated the flow.
- No fault path. One failing record can leave you with a partial run and no alert. Add fault paths to your Create, Update, and Action elements.
- Ignoring daily limits. Scheduled flows have a daily cap on interviews. Check the current Salesforce limits before you point one at millions of records.
If the job is slow, near the limits, or needs custom logic, move it to Batch Apex run by a Schedulable class.
Exercise
A business wants every open case with no activity for 30 days closed automatically at 2 a.m. each night. Which tool fits, and where should the 30-day condition go?
Show answer
A scheduled flow, set to run daily at 2 a.m. on the Case object. Put the status and last-activity conditions in the Start element filter so only matching cases start interviews. Add a fault path to the Update Records element.