Sub topic 11
Choosing which records a scheduled flow processes
This chapter assumes you can open Flow Builder, you know what an object, field, and record are, and you have read the earlier chapters on schedule settings and flow resources. Here you will learn how the Start element decides which records a schedule-triggered flow touches, and how to keep that selection correct, narrow, and safe to repeat.
How the selection works
A schedule-triggered flow can select records in two ways:
- Object and filters in the Start element. At the scheduled time, Salesforce queries the object using your filter conditions. It then runs one flow interview for each matching record. Inside each interview, the record is available as
{!$Record}. - No object. The flow runs a single interview per schedule, with no
$Record. You then use Get Records and a Loop to find the data yourself.
The first approach is usually better. Salesforce does the query and groups the interviews into batches, so you write the logic for one record and it scales to many.
Configuring object and filters
In the Start element, choose Schedule-Triggered Flow, set the schedule, then configure two things.
- Object. Pick the object whose records you want, such as Opportunity.
- Filter conditions. Each condition has a field, an operator, and a value. Combine them with one of three logic types:
- All Conditions Are Met (AND)
- Any Condition Is Met (OR)
- Custom Condition Logic Is Met, for example
1 AND (2 OR 3)
The metadata for a flow that selects open Prospecting opportunities not yet reviewed looks like this:
<start>
<filterLogic>and</filterLogic>
<filters>
<field>StageName</field>
<operator>EqualTo</operator>
<value>
<stringValue>Prospecting</stringValue>
</value>
</filters>
<filters>
<field>Reviewed__c</field>
<operator>EqualTo</operator>
<value>
<booleanValue>false</booleanValue>
</value>
</filters>
<object>Opportunity</object>
<schedule>
<frequency>Daily</frequency>
<startDate>2025-01-01</startDate>
<startTime>02:00:00.000Z</startTime>
</schedule>
<triggerType>Scheduled</triggerType>
</start>Reviewed__c is a custom checkbox field used here for illustration. You would create it in your own org. Its purpose becomes clear in the next section.
If you leave the filters empty, every record of that object is selected. That is rarely what you want, so confirm it is intended.
Make the selection repeatable
A daily flow selects records again every day. If the filter does not exclude records that were already handled, the same records get processed on every run. For example, an email could go out daily, or a task could be created daily.
Use one of these patterns:
- A marker field. Add a checkbox or date field, such as
Reviewed__cabove. Filter on it, and have the flow set it at the end of each interview. - A state change. Process records in a state that the flow itself changes, such as Stage equals Prospecting, which the flow then moves to Qualified.
- A date window. Filter on a date field so each record qualifies only during a limited period.
The marker-field approach is the most explicit. It also makes failures visible: a record that errored out keeps its unchecked box and is picked up on the next run.
Filters versus a Decision element
You can filter inside the flow with a Decision element on $Record, but the Start filter is better for the main selection.
| Approach | Where it runs | Effect |
|---|---|---|
| Start element filter | In the query before interviews start | Only matching records get an interview |
| Decision on `$Record` | Inside each interview | Every record gets an interview, then most exit early |
Use the Start filter for the coarse selection. Use a Decision for conditions that the Start filter cannot express, or for branching to different actions based on a record's values.
Start filters versus Get Records and Loop
The no-object pattern gives you one interview that fetches records and loops over them. It still has uses, such as when you need to combine data from several objects before acting. It has costs, though:
- One interview runs inside one transaction, so the loop shares a single set of governor limits. A single interview also has a cap on how many elements it can execute.
- Get Records returns at most the transaction's record limit, so large data sets can fail or be cut off.
- You must bulkify the work yourself: collect changes in a collection and run one Update Records after the loop, never one inside it.
With an object and filters, the platform batches the interviews for you. Prefer that unless you need cross-object logic.
Edge cases to check
- No matches. If the query returns nothing, no interviews run. This is normal, not a failure.
- Blank values. To select records where a field is empty, use the
Is Nulloperator with the valueTrue.Equalswith an empty string does not do the same thing. - Records change between runs. The query is evaluated at run time, not when you save or activate the flow. A record that matched yesterday may not match today.
- Updating the selected record. Use Update Records with the option to update the record that triggered the flow. If your update changes a field the filter depends on, the record drops out of tomorrow's selection. That is often the desired effect.
- Unsupported field types. Some field types, such as long text areas, cannot be used in filters. If a field does not appear in the filter field list, use a Decision on
$Recordinstead.
A worked checklist
Before you activate a scheduled flow, answer these questions:
- Which object, and which fields define "a record that needs processing"?
- Does my filter exclude records the flow has already handled?
- Is the filter in the Start element, and not left to a Decision?
- How many records will match on a typical day, and on the worst day?
- Have I tested with a deliberately small set of records?
Exercise
A daily schedule-triggered flow on Case selects records where Status equals "Escalated" and sends a notification email to the owner. After a week, owners complain that they get the same email every day for the same cases. What is the cause, and give two ways to fix it.
Show answer
The filter selects every Escalated case on every run, and nothing marks a case as already notified, so each run processes it again. Fix it by adding a marker field such as a "Notified_c" checkbox, adding "Notified_c equals false" to the Start filter, and setting it to true in the flow after the email is sent. Alternatively, add a date filter, such as only cases escalated within the last day, or change the case to a state that no longer matches the filter after notifying.
Exercise
Why is a filter in the Start element generally preferable to a Decision element on $Record as the main way to select records?
Show answer
The Start filter is applied in the query, so only matching records get an interview. A Decision runs inside each interview, so every record of the object is selected first and most interviews exit early, which wastes interviews and counts against the daily interview allowance.