How To Automate Monthly/Quarterly Actions Using Flows ~ Salesforce
Hi all,
In this article (it’s mostly screenshots), I will be talking about using declarative methods to perform actions on a timely basis, i.e. monthly, quarterly etc.
Such popular actions would be creating records, calling a subflow or calling an approval process. Automating these actions to be performed in a timely basis is easier using programmatic code or Apex, but when it comes to declarative methods, this can be quite tricky, because Salesforce only allows daily or hourly frequencies in declarative methods. But there is a way to achieve it and that’s what I will be explaining in this post.
The use case
I believe the best way to learn is through examples and I will be going through a common use case in this post, which is to create quarterly or monthly reports.
In this example, we will be creating a custom record every quarter, that is, the 23rd of March, June, September and December.
The flow elements
Create a new flow and add the following elements (simply drag and drop the elements into the canvas and link them using arrows to represent the flow).
For this we will be using the following structure that incorporates:
- The “Start” element that is triggerred by a schedule.
- Then a “Decision” element is determining if the current date is the 23rd of a month divisible by 3.
- Lastly it will call a “Subflow”, which can be replaced by any supported action you prefer.
Launching the Flow
The first step is to modify the “Start” element as follows so that it will initiate a Flow that runs every day.
- Under “Choose the Flow Trigger”, select “Scheduled Jobs” to launch the flow. This will trigger the flow in a scheduled basis.
- Under “Set a Schedule”, choose an appropriate start date and time and chose “Daily” frequency.
- Since we will be calling a subflow, we will not be needing the last option.
Formula to check the date
Since now we have a daily triggered flow, the next step is to modify the “Decision” element, so that is will check if the current date is valid or not.
According to our use case, which we need to be run quarterly, we will have to use a formula to determine whether the current date is a valid date (i.e. 23rd of March, June, September, December). Let’s create a formula resource as follows.
Under the “Toolbox”, select “Manage” and create a new “Formula” flow resource with the following information.
The following custom formula checks if the current date is the 23rd, and also, if the current month is divisible by 3.
DAY(TODAY()) == 23 && MOD(MONTH(TODAY()), 3) == 0
The Decision element
Now that we have the formula in place, we can use it in the “Decision” element to decide whether to call the subflow or not.
Make sure that the “Outcome” uses our custom formula and it evaluates “True” (which is supported through Salesforce global constants).
Now that we have configured our flow, the subflow action will be called on the 23rd of March, June, September and December and you can configure the subflow to exeute any action you prefer.
Hope you learned something today.
Cheers!