Sub topic 7
Scheduled flows for time-based batch work
This chapter assumes you know how to build a basic flow in Flow Builder, can write a simple SOQL-style filter, and understand objects, fields and records. You should also know what a record-triggered flow is, because scheduled flows are often compared with it.
What a scheduled flow is
A scheduled flow is an autolaunched flow that starts at a set time and repeats on a schedule you choose: once, daily or weekly. It does not wait for a user or for a record change. Salesforce launches it, runs it against a set of records, and finishes.
Use it when the trigger is the clock, not an event. Examples:
- Close tasks that have been open for 90 days.
- Email owners of opportunities whose close date passed last week.
- Set a flag on contracts that expire in 30 days.
- Create a follow-up task for every case still open after a week.
A scheduled flow runs as the Automated Process user by default, not as a person. Keep this in mind when you check field-level security, sharing and the "Created By" value on records the flow creates.
How the schedule and the record set work
When you create a scheduled flow, the start element asks for four things:
- The object to process (optional, but needed for batch work on records).
- Filter conditions that select the records.
- A start date, time and frequency.
- Optionally, whether to run only when a given set of conditions is met.
Salesforce evaluates the filters when the flow starts. It then runs a separate flow interview for each matching record, and it groups those interviews into batches. A flow interview is one running instance of a flow.
The records are processed in batches of up to 200 interviews per transaction. Each batch has its own limits. A failure in one batch does not roll back batches that already finished.
Building one: a worked example
Suppose the business wants every open opportunity whose close date is in the past to get a "Needs Review" flag and a task for the owner. Follow these steps in Flow Builder.
- Create a new flow and choose Schedule-Triggered Flow.
- In the start element, set the frequency to Daily and pick a start time outside business hours, such as 02:00.
- Choose the object Opportunity.
- Add filters:
IsClosedequalsfalse, andCloseDateis less thanTODAY. Salesforce supports a date literal here. - Add an Update Records element that sets a custom checkbox, for example
Needs_Review__c, to true on the current record. - Add a Create Records element that makes a Task with the opportunity's
OwnerIdas the owner andWhatIdset to the opportunity. - Save, run a debug session, then activate.
Because the flow operates on $Record, which is the single record for the current interview, you do not need a loop. Salesforce handles the iteration. This is the main reason to prefer a scheduled flow over a hand-built loop in a screen flow.
You can set the filter to run once per record by adding a flag. In this example, add Needs_Review__c equals false to the filters. Without that guard, the flow would create a new task for the same opportunity every day.
Limits and edge cases
Scheduled flows run under Salesforce governor limits, which are per-transaction caps on queries, DML (data changes) and CPU time. Each batch of interviews is a transaction. These points matter in practice:
- Volume. Each flow is limited in how many records it can process in a day, tied to your org's edition and license limits. Check current numbers in Salesforce help before you plan a very large job.
- Bulkification. Flow bulkifies elements across the interviews in a batch. Put queries and DML in the flow's elements, not in a loop, and the platform combines them. A Get Records or Update Records element inside a loop you built yourself can still hit limits.
- Order of records. Do not rely on any particular order when interviews run.
- Time zone. The start time uses the running user's time zone setting. Daylight saving changes can shift the clock time you expect.
- Delay. The run starts near the scheduled time, not exactly at it. Heavy queue load can delay it. Do not use a scheduled flow where a few minutes matter.
- Record changes by other automation. Updates from a scheduled flow can fire record-triggered flows and Apex triggers on the same object. Plan for this using what you know about the order of execution.
- Errors. Salesforce emails flow errors to the user who last modified the flow. Interview-level errors can be logged, but you must plan how someone sees them.
Scheduled flow or record-triggered scheduled path?
A record-triggered flow can also act later, using a scheduled path. The two overlap, so the difference is worth knowing.
| Question | Scheduled flow | Scheduled path in a record-triggered flow |
|---|---|---|
| What starts it? | The clock | A record create or update |
| What is the delay based on? | A fixed time and frequency | A date field on the record, or the trigger time, plus an offset |
| Does it re-check all records? | Yes, each run applies the filters | No, it handles the records that fired the trigger |
| Best for | Sweeping many records on a regular cycle | An action tied to one record's own date |
If you need "seven days after this case was created", a scheduled path fits. If you need "every night, find all cases still open", use a scheduled flow.
When a scheduled flow is not the right tool
Move to another tool when:
- Volumes are very large or the logic is complex. Batch Apex gives you control over batch size, retries and state between batches.
- You need to run more often than daily. Scheduled flows run at most once per day. Scheduled Apex can run on a more frequent cron schedule, or you can use a platform event or an external scheduler.
- A user must make decisions along the way. Use a screen flow, or an approval process for sign-off.
- You need the work to happen the instant a record changes. Use a record-triggered flow.
Testing and monitoring
You cannot wait for midnight to test. Use these habits:
- Run the flow in a sandbox with a copy of realistic data.
- Use Debug in Flow Builder, which lets you pick a sample record.
- Temporarily narrow the filters to a few test records, then widen them before you activate.
- After activation, review Paused and Failed Flow Interviews in Setup and check Scheduled Jobs for the next run time.
- Add a fault path to every Update Records and Create Records element so one bad record produces a clear message and does not hide the cause.
Example answer for a typical requirement
A requirement reads: "Each Monday, remind account owners of accounts with no activity in 60 days." The signals point to a scheduled flow: it is time-based, it works on many records, and no user needs to take part. The filter is Last_Activity_Date__c less than 60 days ago, plus a flag to avoid repeat reminders. The action is a Create Records element for a Task. Salesforce handles the batching.
Exercise
A scheduled flow runs daily and creates a task for every opportunity whose close date has passed. After a week, owners complain about seven duplicate tasks per opportunity. What caused this, and how do you fix it?
Show answer
The start filters still match each opportunity after the flow has handled it, so every daily run processes it again and creates another task. Add a guard to the filters, such as a checkbox like NeedsReview_c equals false, and have the flow set that checkbox to true when it creates the task. Processed records then drop out of the result set.
Exercise
A requirement says "Send an email 14 days after each contract's end date." Should you use a scheduled flow or a scheduled path in a record-triggered flow? Give one reason.
Show answer
A scheduled path in a record-triggered flow is usually better, because the delay is tied to a date field on each individual record. A scheduled flow would also work if you filter for contracts whose end date was exactly 14 days ago, but then you must guard against missed runs and repeats.