Flow: How To Run a Scheduled Path WITHIN an Hour
Today I want to share a solution that is one of my favorites, yet a very simple one. If you ever work with time-dependent actions in Workflow, scheduled actions in Process Builder, and scheduled paths in Flow, you must have noticed that the minimum time unit is an hour. But sometimes even one hour is TOO LONG! As a result, it can be difficult for admins to troubleshoot the new flow and for users to remember whether they’ve finished the actions or not.
But don’t worry. Let’s resolve this situation with a formula field on the target object!
The Concept of Setting Desired Delay
The concept involves very easy math. Since, at minimum, the tools can only push the delay one hour or more, we can create a formula date/time field and set it to 1 hour + X minutes from now. Then in the flow, we can set the schedule to be 1 hour before the formula field. This means the schedule will fire at the X minutes mark (equation: (1 hour + X minutes) – 1 hour). X here is your desired delay in minutes.
Take the graph below, for example. If we want to fire the scheduled path after only 5 minutes, we need to create a field that is 1 hour and 5 minutes from now (and later, we’ll subtract that hour).
Transform the Concept Into a Formula Field
The second step is to transform this calculation into a formula. First, we need to create a formula field with Date/Time type as Date type will only return the same day.
Then we’ll translate the 1 hour + X minutes from now into formula syntax. To start, we’ll need to define the “Now” time using the Now() function.
Caution: It’s important to note that when you perform addition or subtraction with the Date or Date/Time fields, the unit is always “Days”. So, using “+ 1” in your formula means you’re adding one day. To get hours, we must divide 1 by 24. To get minutes, divide 1 by 1440 (24 x 60). The formula that follows is our goal – 1 hour + 5 minutes from now (again, we’ll subtract one hour later).
Be Extra Careful When Setting the Schedule Time
All set with the field! Now we just need to reference this field in the schedule path and substract one hour. Pay close attention to the Offset Options to avoid any surprises (ex. If we mistakenly choose Hours After (as opposed to Hours Before), it will run 2 hours 5 minutes later, not the intended 5 minutes).
Bonus note! Besides Flow, This method works on Workflow and Process Builder too!
Do Not Put The Formula Field On The Object Page Layout
The formula field is calculated whenever the field is viewed or referenced. If you put it on the page layout, the system will update the field again and again whenever users edit the record. As a result, the scheduled actions will be postponed. This is undesirable as we only want the field to calculate whenever we run the flow.
To avoid this, my suggestion is first to have it on the page layout just so you can confirm the formula is correct, and then remove it so no one sees it.
The Actions Might Not Run At The Exact Moment
Even though we can schedule the actions to run sooner, the actual execution still depends on your system’s capacity. If there are many scheduled actions or jobs running at the same time, you might experience some delays. However, it should still be very close.
Why didn’t you use Zero as the value instead? Using zero would give the same outcome, no? I’ve used zero in past flows and it worked just fine for me.
Hi, by using zero, the system will execute the actions as soon as there is available capacity. We won’t have control on when, so it can happen within the range of 1 second after and 1 hour after (usually very fast though). By using this method we can have a better control on when the actions should be executed. Ex. 10 mins, 20 mins, 30 mins after. It is meant to replicate the standard scheduling but cut the time into a smaller frame, not simply delaying the actions. Hope this explains
Have you ever seen the function not calculate with a value using the Now()? I just utilized this formula and it worked in Salesforce Sandboxes but would not calculate a value from my Production environment. Is there any way to utilize a LastModifiedDate? Or do you have any thoughts on Now() not running and the field remaining blank with no datetime calculation?
In my sandbox the calculation and formula worked as expected, but it seems to never evaluate- I do not have it on a layout in Prod nor in the lower sandboxes…
Hmm it sounds strange that it is not calculating. How did you spot that it’s calculating only in sandbox but not in production? Is it because your flow didn’t fire?
LastModifiedDate could work too, but should be careful as the flow interview will be deferred again if someone edits the record.
If it’s working in sandbox but not in production, I would actually check if the flow or process itself is set up and fired correctly. You can check that from setup > Paused and Failed Flow Interviews.
I thought this was very cleaver, but for me, even though the field is not in a page layout, the formula still updates, and triggers the flow multiple times.