Let us continue with my Lightning Flow, ‘Getting Started’, series. We discussed how different types of Flows enable you to minimize code usage. Until Winter’20 release, Scheduling Autolaunched Flows was out-of-scope. No more!
As we all know, before Winter’20 release, autolaunched Flows could only be launched using Process Builder or Apex. But, that was before! Let us open our present, shall we?
What are Scheduled flows?
Before we unwrap, let us understand what Scheduled Flows are. Scheduled Flows are not triggered by an Event on the data; they simply run when a scheduled time arrives.
Scheduled Flows run as follows:
- Once (On a particular date and time)
- Daily (On a particular date and time)
- Weekly (On a particular date and time)
The best part about Scheduled Flows is that it allows you to specify an Object and a filter to only run for a set of records.
Remember, when a Flow starts, a Flow interview runs for each record that matches the filter criteria – no looping is required. The matching record is stored in the $Record global variable, so you can reference the variable, or its fields, throughout your flow.
Why do we need Scheduled flows?
Do you have Flows that are launched from Process Builder every time a record is created or edited – even though you need them to run only once a day or once a week (like Scheduled Apex provides)? If you had such requirements before winter’20 release, you would have to write Apex code. Or, you would have messed-up your Salesforce org with many unwanted Processes or Flows.
Scheduled Flows provide you the flexibility to run auto-launched Flows on scheduled time (Like daily, weekly or once). Yes, now you have one more way to solve your business needs using clicks not code!
What are some use cases of Scheduled flows?
Thankfully, there are many. Let me list a few:
- Deactivate users on their last day at work.
- Create new users ahead of time and send a welcome email with a new password on the day of on-boarding.
- You may also schedule Flows to cleanse data.
Business Use Case
Edward Backhouse is working as a System administrator at Gurukul on Cloud (GoC). GoC is faced with data integrity issues. Sales reps are not updating Opportunities proactively. This negligence, on the part of Sales Reps, has generated thousands of open Opportunities in the System.
GoC’s upper management wants to address the issue by running a nightly process to update Opportunities to Closed Lost if it matches the following criteria:
- Opportunities’ Account is marked as out-of-business (which can be identified through a checkbox field on the Account name, Out of Business).
- Opportunities’ Close Date was before 90 days from today’s date.
Solution for the above business requirement
To solve this requirement, we will only a few ingredients – including, Lightning Flow a Custom field (Out_of_Buesiness__c) on the Account object.
Before trying to understand the technical aspect of the solution, let us spend some time to understand the general flow of our solution at a very high level. Please spend a few minutes to go through the following flow diagram and understand it.
Using Scheduled Flow, you can streamline the Flow’s logic and create a better performance Flow. Scheduled Flows allow you to specify a filter on an Object and run only for a set of records.
Let us use Lightning Flow to solve the above business requirement. Perform the following steps to create the solution using the new Lightning Flow Designer:
- Log-in into your developer org.
- Create a Custom Field (Out_of_Business__c) on the Account object.
- Navigate to Setup (Gear Icon) | Setup | Process Automation | Flows.
- You’re now on the Flow management page. Based on your current org setting, you may see the following buttons:
- Now click on the New Flow button, it will open a pop-up. Perform the following actions on the pop-up screen:
- Next, we will use the Start Element to filter out Account records and, set schedule time, including other details. Double clicks on the Start Element. Follow the steps as shown in the video:
- The next step is to create a formula to figure out a date that is exactly ninety days before today (the day when flow runs). Click on the Manager | New Resource and creates a formula – as shown in the following screenshot:
- Next, we will use the Record update element to update the open opportunities which have a close date that is exactly ninety days before today (the day when flow runs). Drag and drop a Record update element onto the Lightning Flow Designer – Check out the video for step-by-step instructions:
- In the end, Edward’s Flow will look like the following screenshot:
- Once you’re done, Save the flow and name it Manage Open Opportunities for OOB accounts with Type: Autolaunched Flow. Do not forget to activate the Flow by clicking on the Activate button.
- Woohooo, you have just created a scheduled Flow using Lightning Flow Builder.
Monitor your schedule flow
To monitor Flows that are scheduled, navigate to the following path:
- Navigate to Setup (Gear Icon) | Environments | Jobs | Scheduled Jobs.
- Now look for your Scheduled Flow displaying information as shown in the following screenshot:
- Use Del link to delete Scheduled Flow job from the queue.
It’s time to test the Process
To test the Scheduled Flow, I’ve updated the schedule run time to 11/12/2019 12:40 AM. At this time, the Scheduled Flow ran and updated the Opportunity Stage to Closed Lost. Attached please find the screenshot for your reference:
Monitor your schedule flow
- The Automated Process user runs Scheduled Flows.
- A Scheduled Flow can run only from a schedule.
- If a Scheduled Flow is deleted from the Scheduled Jobs page, the Flow’s status remains active.
- The Start Time field value is based on the org’s default time zone.
- When you define multiple filters, the filter logic usually defaults to AND. However, if multiple filters have the same field selected, and use the equal operator, the filters are combined with OR. For example, your filter checks whether an Opportunity Stage equals Closed Won (1); Stage equals Closed Lost (2); and, Closed Date equals today (3). At run time, the filters are combined to (1 OR 2) AND 3.
- You have a per-org 24-hour limit for the number of Scheduled Flow executions at the scheduled start time. The org limit is the greater number between 250,000 records or the combined total of 200 records per user license. When a Flow is scheduled to start, make sure that its schedule and conditions don’t cause your org to go over the limit
I hope you learned something valuable today and understood how to use schedule flow! Who knew? that learning could be so much fun!!
–> Please feel free to add constructive comments and insights to the blogs.
Proofreader: - Munira Majmundar