Skip to main content
TrailblazerDX, the ultimate AI learning event is heading back to San Francisco March 6-7, 2024. Register Now and save 35% with code T24DEYE424.

Schedule a Flow

Learning Objectives

After completing this unit, you’ll be able to:

  • Create a flow that runs at a predetermined time.
  • Run a schedule-triggered flow for every record that matches certain conditions.
Note

This badge is one stop along the way to Flow Builder proficiency. From start to finish, the Build Flows with Flow Builder trail guides you through learning all about Flow Builder. Follow this recommended sequence of badges to build strong process automation skills and become a Flow Builder expert.

Schedule-Triggered Flows vs. Scheduled Paths

In the Record-Triggered Flows badge, you learn about scheduled paths. Scheduled paths can run elements a certain amount of time after a trigger, or before or after a date on the triggering record. They rely on a record being created, updated, or deleted. What if you want to run automation that’s not triggered by a record, but at a specific time or on a specific schedule? For that, you need a schedule-triggered flow. 

The Schedule-Triggered Flow type is part of the Autolaunched Flow family. It’s like a quiet younger brother who’s easy to forget but nevertheless is quite dependable. 

When you need to run something on a schedule, consider these differences between scheduled paths and schedule-triggered flows.

Consideration Scheduled Paths Schedule-Triggered Flows

Flow Type

Record-Triggered

Schedule-Triggered

Trigger

A record is created, updated, or deleted

A specific date and time

What Time

A specified amount of time after the trigger

or

A specified amount of time before or after a date on the triggering record

A specific date and time

Frequency

Runs once for each time it’s triggered

Can run once, daily, or weekly

Why Use Schedule-Triggered Flows?

Schedule-triggered flows can run once, daily, or weekly, depending on how you configure them. They truly are automated automation! Use schedule-triggered flows to handle regular tasks such as maintaining your org’s data or sending messages to your users. Here are a few examples of what scheduled flows can do for you.

  • Automatically escalate open tasks or cases that have been open too long.
    Raise the priority or change the status to something that gets more attention. You can also notify key personnel of the escalation. “Hey Sal, this task has been open for 42 days.”
  • Check contacts for missing field values and send their creators an email reminding them to fill in the data.
    Sometimes users need to create a record before they have all the required data. A schedule-triggered flow can remind them to fill in those important values at a later date. “You really should have that contact’s email address by now, Sal.”
  • Push a batch of changes overnight.
    If you can define changes in a flow, you can push them in batches. You can’t push updates from a CSV file, but you can, for example, reassign all of Sal’s accounts in the Northwest territory to someone else if he doesn’t improve his data entry by next week. (Though you probably shouldn’t do that unless his manager requests it!)

A user sitting at his desk with a sheepish smile and a shrug. Flo Smith is standing beside him, looking disapproving and gesturing to his screen.

In many cases, you could use either scheduled paths or schedule-triggered flows. The main difference is that a scheduled path runs based on a record change, whereas a schedule-triggered flow does all of its work at a specific time and at a specified frequency. Consider the example of automating reminders for contact creators to add missing field values. 

A scheduled path can email each contact creator a few days after the contact is created. The timing is based on the contact creation date and the scheduled path runs once. 

A schedule-triggered flow can send out all the notices for all incomplete contacts every Sunday night, so all creators can deal with all their data woes all at once first thing on Monday. The timing is set, the flow runs every week, and if a record isn’t corrected, its creator gets a reminder every Sunday until those missing field values are fixed.

To summarize, use a schedule-triggered flow when you want the flow to:

  • Run at a specific time.
  • Run independent of a record change.
  • Run through many records at one time.
  • Run daily or weekly.

Pyroclastic’s support managers want an ongoing record of the number of high priority cases they have at the start of each day. To record this metric in a reportable way, Flo asks you to create a custom object to store each day’s case count and build a schedule-triggered flow to record the count.

Before You Start

There are three settings to define before you start creating schedule-triggered flows. Some of these settings are likely already set in your production org, but it’s a good idea to confirm them. Make sure that these settings are correct in the Trailhead Playground you’re using for this badge before you create a scheduled flow.

  1. Set the Default Workflow User.
    To run a schedule-triggered flow, Salesforce needs to know which user runs the flow. Make sure there’s a Default Workflow User selected on the Process Automation Settings page in Setup.
  2. Set the Automated Process User Email Address.
    If your schedule-triggered flow sends emails, Salesforce needs an email address to use as the sender. To set this address, first define it as an organization-wide email address. Then, enter that organization-wide email address in the Automated Process User Email Address field, on the Process Automation Settings page in Setup.

    The Process Automation Settings page. Default Workflow User is Flo Smith and Automated Process User Email Address is fsmith@pyroclastic.com.
  3. Set the Default Time Zone.
    Schedule-triggered flows are based on your Salesforce org’s default time zone. Find this setting on the Company Information page in Setup. To prevent unwanted timing surprises, confirm this setting before you schedule a flow. Keep in mind that if you change the default time zone, that may change the timing for other things in your org.

    “”

Create a Custom Object

First you create the custom object to store the daily case count.

  1. Create a custom object:
    1. Label: Archived Metric
    2. Plural Label: Archived Metrics
    3. Starts with vowel sound: Checked
    4. Record Name: Archived Metric Number
    5. Data Type: Auto Number
    6. Display Format: Archive-{000000}
    7. Starting Number: 1
    8. Allow Reports: Checked
  2. Create a custom field on the Archived Metric object:
    1. Data Type: Number
    2. Field Label: Value

Schedule a Flow

With a few exceptions, schedule-triggered flows have the same components and abilities as most other flow types. Check out Schedule-Triggered Flow Considerations for more info.

  1. Create a schedule-triggered flow.
  2. Set the flow’s schedule:
    1. Click Set Schedule.

      The Start element with two menu items: Set Schedule and Choose Object (Optional)
    2. For Start Date, enter tomorrow’s date.
    3. For Start Time, enter the current time.
    4. For Frequency, select Daily.
  3. Add a Get Records element:
    1. Label: Get High Priority Cases
    2. API Name: Get_High_Priority_Cases
    3. Object: Case
    4. Condition Requirements: All Conditions Are Met (AND)
    5. Field: Priority, Equals, High
    6. Field: IsClosed, Equals, $GlobalConstant.False
    7. How Many Records to Store: All records
    8. How to Store Record Data: Automatically store all fields
  4. Create a Variable resource:
    1. API Name: caseCount
    2. Data Type: Number
    3. Decimal Places: 0
    4. Default Value: 0
  5. After the Get Records element, add an Assignment element:
    1. Label: Count Cases
    2. API Name: Count_Cases
    3. Set Variable Value: caseCount, Equals Count, Cases from Get_High_Priority_Cases
  6. After the Assignment element, add a Create Records element:
    1. Label: Create Archived Metric
    2. API Name: Create_Archived_Metric
    3. How Many Records to Create: One
    4. How to Set the Record Fields: Use separate resources, and literal values
    5. Object: Archived Metric
    6. Field: Value__c
    7. Value: caseCount
  7. Save the flow. For Flow Label, enter Daily High Priority Cases.

    The flow canvas showing all the flow elements corresponding to the preceding instructions.

After you activate a flow, it runs according to the scheduled frequency. Unfortunately, flows aren’t time machines. If you schedule a flow to start at a time in the past, it can’t go back in time to run at that earlier date and time. Instead, the first run happens according to the scheduled frequency. For example, if you set a flow to run weekly starting on a Tuesday, and you activate it on a Wednesday, the flow runs for the first time on the next Tuesday.

Update Multiple Records with the $Record Global Variable

In a record-triggered flow, you can use the $Record global variable to access and update the record that triggered the flow. You can also use $Record in schedule-triggered flows. So, which record does $Record refer to in a schedule-triggered flow?

On schedule-triggered flows, the $Record global variable actually refers to multiple records. When you select a schedule-triggered flow’s Start element, you have the option to click Choose Object, then select a Salesforce object and define criteria.

The Start element with object set to account

When the flow runs, it finds all of that object’s records that match the criteria, and makes them available through $Record. If you don’t set an object and criteria, $Record isn’t available. 

Because this criteria finds records from only one object, and the same actions are performed for all of those records, the flow can process all the records in a large group called a batch. Salesforce processes batches more efficiently than a series of single records, so batch processing is usually faster and less likely to exceed governor limits.

A banana’s journey from harvesting to grocery store shelves, corresponding to the analogy that follows.

Think of batches of records like bananas; when you work with them, you work with multiple bananas together in a bunch. They grow in a bunch, and they’re harvested in a bunch, transported as a bunch, even sold in stores as a bunch. Handling bananas in bunches makes everything done with bananas simpler and faster. Batch processing does the same for Salesforce records.

Use $Record in a Schedule-Triggered Flow

When you set criteria in the Start element of an Autolaunched flow, two changes occur. 

  • In all of the flow’s elements, $Record is available as a global variable.
  • In the Update Records element, under How to Find Records to Update and Set Their Values, there are two new options:
    • Use the $Record global variable: Use this option to update all the records that match the start criteria in one batch.
    • Update records related to the record that triggered the flow: Use this option to update all the child records for one related object, such as all the contacts related to the triggering account.

      How to Find Records to Update and Set Their Values settings corresponding to the preceding descriptions

Lately, Pyroclastic employees across multiple teams are finding lots of accounts with no contacts. Sales leadership wants to address the problem but they don’t have an efficient way to identify accounts that need attention. Flo asks you to create a schedule-triggered flow that runs weekly and posts to Chatter alerting managers about accounts that have no contacts.

Build a Schedule-Triggered Flow

  1. Create a schedule-triggered flow.
  2. Set the schedule:
    1. Start Date: tomorrow’s date
    2. Start Time: the current time
    3. Frequency: Weekly
  3. Click Choose Object.
  4. For Object, select Account.
  5. For Condition Requirements, select None—Run Flow For All Accounts.
  6. Add a Get Records element:
    1. Label: Find Contacts
    2. API Name: Find_Contacts
    3. Object: Contact
    4. Condition Requirements: All Conditions Are Met (AND)
    5. Filter: AccountId, Equals, $Record > Id
    6. How Many Records to Store: Only the first record
    7. How to Store Record Data: Automatically store all fields
  7. After the Get Records element, add a Decision element:
    1. Label: Contact Found?
    2. API Name: Contact_Found
    3. Define one outcome:
      1. Label: Yes
      2. Outcome API Name: Yes
      3. Condition Requirements to Execute Outcome: All Conditions Are Met (AND)
      4. Resource: Contact from Find_Contacts
      5. Operator: Is Null
      6. Value: $GlobalConstant.False
    4. Change the label for the default outcome to No
  8. Create a text template resource:
    1. API Name: ChatterBody
    2. Body: @[{!$Record.Owner.ManagerId}] This account has no contacts.
      Owner: @[{!$Record.OwnerId}]
  9. On the No path, add an Action element:
    1. Action: Post to Chatter
    2. Label: Chatter Post to Manager
    3. API Name: Chatter_Post_to_Manager
    4. Message: ChatterBody
    5. Target Name or ID: $Record > Id
  10. Save the flow. For Flow Label, enter Weekly Check for Contacts.

Resources

Keep learning for
free!
Sign up for an account to continue.
What’s in it for you?
  • Get personalized recommendations for your career goals
  • Practice your skills with hands-on challenges and quizzes
  • Track and share your progress with employers
  • Connect to mentorship and career opportunities