Shows how to link Business Hours (or other native logic) directly into Salesforce flows. Uses concepts already found in formula fields such as the $Flow.InterviewStartTime global variable.
Here's a scheduled flow demo. But I want the schedule only on business days.
First we'll create an action called Within Business Hours and this is a Streamscript action. This action links flow with the Business Hours logic in Salesforce. And I'll come back in a second to fill it in.
Next is the decision. I set the path to Run when the action returns true. Boolean equals true.
Otherwise we will End the flow; this is the default when the decision is false. And I use the End step here just for the Run path.
I will send an email using the Send email action and with a test message so that I know the flow runs.
Back to the Business Hours. I click on the action to edit the Streamscript, and it shows these standard Salesforce commands including Business Hours IsWithin so, using IsWithin, it has two parameters: Business Hours ID, and the Date/Time.
In setup, I have Business Hours for Eastern Standard Time.
It's Monday to Friday with some holidays configured already.
I'll copy and paste the name or the ID will work too.
Then I'll use the Flow Interview Start Time. That's a standard Flow global.
Now it's ready to test. Friday is a weekday, so this should run anyway.
Click Save, click Debug.
Let's look at the results. It decided that we're within Business Hours and it runs the left path and the email comes in.
But what I really want is to test it on a specific date. So let's create a new resource "now" and set its date to the 4th of February.
So that's hard coded as the 4th February for now.
To use the variable I'll edit Within Business Hours and I'll type in the date here.
It's ready to test again. The 4th February is a Saturday and is outside business hours.
Click Save and click Debug. It decided that we are outside business hours and stopped, which is good.
As a final step, I'll update that variable to use the Interview Start Time.
So summing up: we needed a flow to run on business days. We used the native Business Hours logic in Streamscript. Then we used Date formulas to test the flow runs correctly. It decided that we are outside business hours and stopped, which is good. As a final step, I'll update that variable to use the Interview Start Time. So summing up: we needed a flow to run on business days; we used the native Business Hours logic in Streamscript; then we used Date formulas to test the flow runs correctly.
Getting started with Streamscript
Install from the Salesforce AppExchange
Package install link: /packaging/installPackage.apexp?p0=04tGA000005NDq5
Syntax Highlighter |
HTTP Callouts |