Need help creating and deploying a scheduled flow? Here's a step-by-step guide, written by one of Gearset's Community Advisors - the wonderful Michael Halliwell. This article assumes you already have base knowledge around the logic and data elements of flows.
An example use case for scheduled flows
The Accounting department manages the activation and deactivation of accounts in Salesforce. Currently, they're running reports each week and manually updating the status of accounts to active or inactive based on the contract start/termination dates. Accounting has requested automation that looks at the contract start/termination dates every night and automatically activates or deactivates these Accounts.
Creating the scheduled flow
First, we'll need to create a new flow, selecting the Autolaunched Flow option upon creation.
Next, double click on the Start element to open the start options. With the start options open, select 'Scheduled jobs' under 'What Launches the Flow'. Choose your start date, start time, and frequency to set when and how often you want this flow to run.
For our example, I'll be scheduling the flow to start on the 13th of July, and then run every night at 1:30AM.
It's important to note that the Start element is acting like a Get Records element. When it runs, it's actually going to run this flow for one record at a time. Each record it finds gets stored in a single record variable called
$Record, so you won't need to loop through your results.
Since our Start element is finding our records, we must choose which object will be queried when the scheduled flow launches. For my use case, I've selected the account object. You can set up criteria to filter down the accounts you query, but there's no option for
OR logic and no ability to add custom logic such as
1 AND 2 OR 3. But if necessary, you can do this in a Decision element later on in the Flow.
As we're trying to activate or deactivate these accounts automatically, based on contract start/termination date, it would be smart to be able to add a formula variable that returns today's date, and add custom criteria that says
contract start date = TODAY() OR contract termination date = TODAY(). This would narrow my results down, but unfortunately since we cannot add custom OR logic in this node, we'll just have to get all records and filter down later in the flow.
Once you've finished filling out your Start element, select Done.
Now we need to determine whether the account the flow is currently on should be terminated or activated. For this we'll add a Decision element. But before we do that, let's create a formula variable that returns today's date so that we can use it in the Decision element:
Now we have a formula that returns today's date, we can reference it in our Decision to see if the account should be terminated or activated.
Now that our Decision is created, we'll need two Assignments - one after each decision outcome. Each assignment will assign a status of active or inactive to the current record in the flow.
Notice how I am once again referencing the
The next step is to connect the elements, so the flow looks something like this:
Finally, we need to add an Update element. Both Assignments can terminate to the same Update element, as they both reference the some record variable
$Record. This Update element looks like this:
Attach your last lines to the Update Records element, save the flow - and you're ready to activate it! The end result will look something like this:
Deploying the scheduled flow using Gearset
Once you've finished creating your scheduled flow, it can be deployed along your release pipeline using Gearset.
Make sure that your metadata filter for the comparison includes
At the comparison screen, select the flow. Gearset will recognize the dependencies and add those to the deployment package.
Click Next. From the deployment summary page, it's a good idea to validate the deployment by clicking the button in the bottom-right corner.
Assuming everything looks fine after validating, you're ready to hit Deploy now!
Try it for yourself!
You now know how to create scheduled flows and deploy them with Gearset! 🥳 If you want to try out deploying flows or any other metadata types with Gearset, it's completely free to try out for 30 days! Just click the button anywhere on the site to get started. Happy deploying!