Scheduled Flows for the Win

By

An #AwesomeAdmin for a non-profit art school recently reached out to me with a problem. She adopted the school’s org a while back and has helped them make small changes over time. This #AwesomeAdmin, Sam, (real names have been changed) got a frantic email from the school’s program administrator saying that Salesforce was broken! As it turns out, some years-old custom rollup fields no longer worked. 

The fields showed the number of students (Contacts) in each household (Account) that were enrolled in a program (custom object) and listed all the primary and secondary programs for all the students in the household. The school’s enrollment window had already started, so any delay in finding a solution would mean more data that would need to be cleaned up. Sam needed to fix things, and fast. 

Fortunately for Sam, we have a declarative solution. Check out how scheduled flows helped her and how you might use them, too: 

What Is a Scheduled Flow and Why Should I Use It?

Scheduled Flows were released in Winter ‘20. They give you the ability to run an autolaunched flow (one that doesn’t have a user interface screen) on a daily or weekly schedule. Why would you want to do this?

There are a lot of reasons why it might help to delay or schedule the processing of automation. You may want the automation to run at a specific time due to integration with other systems, or specific data requirements. In Sam’s case, the art school is already behind the ball. Their student data is being changed and the Account data is becoming more and more out of date. Whatever reasons you may have for using them, Scheduled Flows are a nice option to keep in your back pocket. 

The Flow Overview

For those more familiar with Flow, here’s a quick overview (there’s a detailed play-by-play just ahead). This flow has six basic elements that we will look at in-depth below. Like all flows, we have a “Start” element. This allows us to set the rules around when the flow runs; we will use it to schedule the flow and choose our starting data. 

scheduled flows start element

Next is a “Get Records” element where we will get the student Contact records that relate to the household Account. We will then review each student with the “Loop” element. For each student in the loop, we will (using two “Assignment” elements) update our rollup and add a semicolon. 

When there are no more students left, we will use the “Update Records” element to update the household account that started the flow. You can read the flow by following the arrows, starting from the leftmost “Start” element. 

The Play-by-Play

Within the Flow Builder, we can select the start node and change the Flow Trigger to Scheduled. We can then set the start date/time and frequency. We can also filter down the records that we want the flow to process. Sam set her flow to only look at Accounts with a Type of Household. Household accounts are standard with the Nonprofit Success Pack

edit a flow screen

Every record that the flow finds will be run through the flow on its own. There’s no need for Sam to create a loop to move through the Household Accounts. She can just create a flow that will count the number of Student records and collect their programs.

Sam is able to use a global variable, specifically {!$Record.Id} as the Id of the Account the flow is currently working on. She configures a Get Records element so that the flow pulls all the Student Contact records that relate to the Account.

edit get records field in a flow

Sam only needs some data from the Student records. She will always have the Id, but she also keeps the Program 1 and Program 2 fields. These are the text fields that have the values she needs to collect and put on the Account. Note that she’s storing All Records, not just the first one. 

edit get records in a flow

Sam uses a Loop Element to review each Student. Each record that passes into the loop goes into an Assignment Element. The one Assignment Element can do a lot of lifting. She creates a number variable to hold the number of students and adds 1 to it. She also creates text variables to store the running list of Program 1 and Program 2. She adds the Students’ programs to their respective variables.   

loop element in a flow

She realizes that adding the program names together won’t look good. If the first student’s program is Vocal Performance, and a second student’s program is Dance, then the result will be “Vocal PerformanceDance” and we can’t have that. Sam decides to, for the sake of simplicity, just create another assignment that adds a semicolon to the program variables after each loop. 

Sam connects the Assignments back to the Loop and adds an Update Record element. The record update will use the values from the Assignment element to update the account that the flow was currently processing. 

update record element in a flow

Sam sets the start time for the following Friday and activates her flow. She tells the nonprofit’s program administrator that everything will work out. That Friday, Flow auto-magically updates every household account with the rolled-up data and will run every Friday going forward. 

Flow may seem intimidating, but it’s worth playing with. Any work that required collecting records used to require code or a third-party application, but now #AwesomeAdmins can take charge with stronger automation tools that are available using declarative tools. If you’d like to start learning more about Flow, check out the Automate Your Business Processes with Lightning Flow trail on Trailhead.

Duplicate a Record with Lightning Flow in Spring ‘20

#AwesomeAdmin Melissa Hill Dees wondered aloud to the Trailblazer community on Twitter how she could duplicate a Salesforce record while updating some of the fields using only declarative tools. Melissa says, when a record meets a specific criteria, “I want to duplicate the record, adjust some values, and save the new record.” This made me […]

READ MORE

10 Game-Changing Flow Solutions

Lightning Flow makes it possible to build seamless experiences for your customers and employees with as little code as possible. By applying the power of low-code, drag-and-drop functionality to customer engagement, you can automate the complex logic of your business process in Salesforce – even if you need to interact with external systems. Two builders […]

READ MORE

Have an Idea for a Story?

We are all about the community and sharing ideas.
Do you have an interesting idea or useful tip that you want to share?

SHARE YOUR IDEA