How to Achieve Pause Behavior with Salesforce Record-Triggered Flows
Why Use Flows?
Flows are a powerful tool any Salesforce adopters can take advantage of. A personal favorite of ours at VPS is a record-triggered flow. The record triggered flow allows you to automatically perform actions in Salesforce, in the background based on Create, Update, or Delete Record Events. Record-Triggered flows remove the need for your staff to perform repetitive tasks, notifications, and updates that need to occur after a record is changed. However, it still has some limitations. For example, record-triggered flows do not allow you to use the “Pause” condition or kick-off a sub-flow. This is because flows are considered to be blocking to allow for result validation, similar to traditional Apex Triggers. Oftentimes, your use-case calls for this type of behavior though, so what should you do? Today, I’m going to provide a real-world example and provide you with the tools to work around this issue.
Use Case Example
Speedy Car Service Inc. uses Salesforce to track their customers (Contacts) and car service requests (Cases). Speedy also uses a Salesforce Public Calendar to track which Mechanics are on shift. When a Customer creates a service request, Speedy’s business process requires that a text message should be sent to the Mechanic on duty. Speedy is able to send SMS messages using Invocable Apex actions included with the Twilio For Salesforce package. However, Speedy does not operate 24 hours a day. If a customer submits a request during off-hours, they want the next Mechanic who’s working to receive a text at the start of their shift.
In this example, we’ll be setting up a record-triggered Flow for the Case object to automatically alert the Mechanics when a new service request is created. Specifically, we’ll be checking if there is a Mechanic currently on a shift by querying the Public Calendar. If there isn’t one working, we’ll have to create a Custom object to send a message to the Mechanic. We’ll get more into detail why that needs to be done later.
Setting Up Objects
Before building the Flow, we’ll need a few objects in place. For starters, you’ll need to create a Public Calendar that controls all of your Mechanics shifts. We’ll call it “Shift Schedule”.
You’ll also need to create two custom objects, “Mechanic” and “Delayed Mechanic Message.” “Mechanic” is needed to associate your Mechanics to the events on the calendar and “Delayed Mechanic Message” will be used to trigger a record-triggered flow for when Mechanics aren’t on shift. “Delayed Mechanic Message” contains custom fields for the outgoing message, related Case record, Mechanic phone number that should receive the message, and most importantly, the “Send Message Time” for when the message is scheduled to go out. You also need to ensure that “Allow Activities” is selected for the “Mechanic” object, so that your Mechanics can be related to Events created on your Salesforce Public Calendar.
Now that this is in place, you can create Events and assign them to the “Shift Schedule” calendar while making the “Related To” field equal to the Mechanic that’s on shift.
Set up Your Main Record-Triggered Flow
Now that the calendar and objects are set up, the flow can be created. The flow above is a record-triggered flow when a Case record is created. As a reminder, Case records represent a customer requesting service on their car. When this flow is initiated, it checks the Calendar to see if there is a Mechanic on an active shift. If there is, it sends that mechanic an SMS message (using the Apex Action from the Twilio for Salesforce Package) letting them know a service request has been made. If there is not, the flow checks for the next Mechanic on staff to send a message.
However, Speedy doesn’t want their Mechanics to get text messages at all hours of the day just because they are next on shift. How can Speedy make sure of this without record-triggered flows being able to put in a “pause” condition in the flow? Instead of a pause condition, Speedy can create a custom object for delayed messages.
Use a Scheduled Path to act like a Pause in a Record-Triggered Flow
The delayed message record then initiates another record-triggered flow. However, this record-triggered flow will run on a scheduled path. This scheduled path can be set to a dynamic value based on a field. In our case, we will use the “Send Message Time” field that is part of the “Delayed Mechanic Message” Custom Object. We set this value to match the next shift when we created the record in the previous flow. This allows the text message to be sent at the start of the Mechanics shift instead of immediately to the Mechanic who has the next shift. Finally, we update a few fields in the delayed message record to indicate that it was sent out.
Even though you can’t run sub-flows and “pause” conditions within record-triggered flows, there are tools within Salesforce to create the same behavior. Understanding how to get the most out of Flows can help automate repetitive tasks for your organization.
Interested in more tips to optimize and automate your Salesforce instance? Learn more about VPS’s Salesforce practice here.