Last Updated on February 10, 2022 by Rakesh Gupta
Big Idea or Enduring Question:
Is your Org cluttered with pending approval requests? Why not reassign the requests to a User (Chief Financial officer) or Queue? Ah, a clean org does feel good, doesn’t it?! Awesome!
An approval process is an automated process an organization can use to approve records in Salesforce. One can create, either a one-step or a multi-step, approval process in Salesforce based on business needs.
In the past, I have written a few articles related to the Approval Process and automation. Why not check them out while you are at it?!
- Getting Started with Salesforce Flow – Part 43 (Dynamic Approval Routing in Salesforce)
- Getting Started with Salesforce Flow – Part 31 (Auto Submit Record into Approval Process with Flow)
- Getting Started with Process Builder – Part 98 (What say? Send an Opportunity Approval Request to a Queue? Really?)
- Getting Started with Process Builder – Part 25 (Auto Submit Record into Approval Process)
Let us take a simple use case – Auto-Reassign Pending Request to Record Owner’s Manager.
Wait a minute, you yell! I know Salesforce enough to know that an approval request cannot be auto-reassigned to anyone unless there is automation. I know you know! So, in this article, let us learn how to create an automation process to auto-reassign the approval process!
Objectives:
After reading this article, you’ll be able to:
- Use Schedule-Triggered Flow to check for pending approval requests
- Use Schedule-Triggered Flow to automatically re-assign pending approval requests to a user
Business Use case
Warren Mason, Gurukul on Cloud (GoC) awesome System Administrator, received the following requirement – develop an automated process (Which runs every morning at 08:00 am) that will automatically assign pending approval to the company’s Chief Financial officer (Nathan Gilmore) after 6 days of its initial submission if, by then, the approval is still pending.
Automation Champion Approach (I-do):
While this can be solved using various automation tools like Apex, etc, we will use Scheduled-Triggered Flow.
Before proceeding ahead, you have to understand the ProcessInstanceWorkItem object. It represents a user’s pending approval request.
Field Name | Details |
ActorId | The Id of the user who is currently responsible for approving an approval request. |
OriginalActorId | The Id of the user who was originally assigned this approval request. |
SystemModstamp | It is the date and time when a record was last modified by a User or by an automated process (such as a trigger.) |
Before discussing the solution, let me show you a diagram of a Process Flow at a high level. Please spend a few minutes to go through the following Flow diagram and understand it. Let’s begin building this automation process.
Guided Practice (We-do):
There are 7 steps to solve Warren’s business requirement using Schedule-Triggered Flow. We must:
- Define flow properties for scheduled-triggered flow
- Add a formula to calculate 6 days before today
- Add a decision element to check, if the step is waiting for approval for 6 or more days
- Add a get record element to find the role CFO id
- Add a get record element to find CFO user-id
- Add an assignment element to assign the CFO user id to actor id
- Add an update records element to update the actor id for pending approval request
Step 1: Salesforce Flow – Define Flow Properties
- Click Setup.
- In the Quick Find box, type Flows.
- Select Flows then click on the New Flow.
- Select the Schedule-Triggered Flow option and click on Next and configure the flow as follows:
- Select None-Run Flow For All Approval Requests.
- Click Done.
Step 2: Salesforce Flow – Create a Formula to Calculate 6 Days Before Today
- Under Toolbox, select Manager, then click New Resource to create a formula to calculate 6 days before today.
- Input the following information:
- Resource Type: Formula
- API Name: forDT6DaysBeforeToday
- Data Type: Number
- Decimal Places: 0
- Formula: {!$Flow.CurrentDateTime} – 6
- Click Done.
Step 3: Salesforce Flow – Using Decision Element to Check if it is Waiting For Approval 6 or More Days
Now we will use the Decision element to check the formula from step 2 to find if the current step is waiting for approval for 6 or more days.
- Under Toolbox, select Element.
- Drag-and-drop Decision element onto the Flow designer.
- Enter a name in the Label field; the API Name will auto-populate.
- Under Outcome Details, enter the Label the API Name will auto-populate.
- Condition Requirements to Execute Outcome: All Conditions Are Met (AND)
- Row 1:
- Resource: {!$Record.SystemModstamp}
- Operator: Less Than or Equal
- Value: {!forDT6DaysBeforeToday}
- Row 1:
- Click Done.
Step 4: Lightning Flow – Adding a Get Record Element to Find the Role CFO Id
The next step is to use the Get Records element to find the role CFO id.
- Under Toolbox, select Element.
- Drag-and-drop Get Records element onto the Flow designer.
- Enter a name in the Label field; the API Name will auto-populate.
- Select the UserRole object from the dropdown list.
- Select All Conditions Are Met (AND).
- Set Filter Conditions
- Row 1:
- Field: DeveloperName
- Operator: Equals
- Value: CFO
- Row 1:
- How Many Records to Store:
- select Only the first record
- How to Store Record Data:
- Choose the option to Automatically store all fields.
- Click Done.
Step 5: Lightning Flow – Adding a Get Record Element to Find the CFO User Id
The next step is to use the Get Records element to find the CFO user’s id.
- Under Toolbox, select Element.
- Drag-and-drop Get Records element onto the Flow designer.
- Enter a name in the Label field; the API Name will auto-populate.
- Select the User object from the dropdown list.
- Select All Conditions Are Met (AND).
- Set Filter Conditions
- Row 1:
- Field: UserRoleId
- Operator: Equals
- Value: {!CFO_Role_Id.Id}
- Row 1:
- How Many Records to Store:
- select Only the first record
- How to Store Record Data:
- Choose the option to Automatically store all fields.
- Click Done.
Step 6: Salesforce Flow – Using Assignment Element to Assign CFO User Id to Actor Id
- Under Toolbox, select Element.
- Drag-and-drop Assignment element onto the Flow designer.
- Enter a name in the Label field; the API Name will auto-populate.
- Set Variable Values
- Row 1:
- Field: {!$Record.ActorId}
- Operator: Equals
- Value: {!CFO_User_Id.Id}
- Row 1:
- Click Done.
Step 7: Salesforce Flow – Using Update Records Element to Update the Actor Id
- Under Toolbox, select Element.
- Drag-and-drop the Update Records element onto the Flow designer.
- Enter a name in the Label field; the API Name will auto-populate.
- For How to Find Records to Update and Set Their Values select Use the IDs and all field values from a record or record collection.
- Map Select Record(s) to Update:
- Record or Record Collection: {!$Record}
- Click Done.
In the end, Warren’s Flow will look like the following screenshot:
Once everything looks good, perform the steps below:
- Click Save.
- Enter Flow Label the API Name will auto-populate.
- Click Show Advanced.
- Type: Schedule-Triggered Flow
- API Version for Running the Flow: 51
- Interview Label: Reassign Pending Approval Requests {!$Flow.CurrentDateTime}
- Click Save.
Almost there! Once everything looks good, click the Activate button.
–> Check out the video for step-by-step instructions instead of reading:
Monitor Your Schedule Flow
To monitor Flows that are scheduled, navigate to the following path:
- Navigate to Setup (Gear Icon) | Environments | Jobs | Scheduled Jobs.
- Now look for your Scheduled Flow displaying information as shown in the following screenshot:
- Use the Del link to delete the Scheduled Flow job from the queue.
Proof of Concept
Every morning at 8:00 AM, a scheduled job will run and start reassigning approval requests to the CFO if the request has been open for approval for 6 days or more.
- Before running the job, there are three records that are waiting for approval for more than 6 days. Currently, it is assigned to Rakesh Gupta.
- Check out the following screenshot, after the schedule-triggered flow finished. All three records now assigned to CFO (Nathan Gilmore)
Formative Assessment:
I want to hear from you!
What did you learn from this post, is it relevant to you, and how will you modify the concepts taught in the post for your own business processes?
Make a post and tag me on Twitter @automationchamp, using #AutomationChampion.
is there a way for the flow to make a decision acording to the record? For example, if the record has a total value higher than 1000, send to approver A, else, approver B, instead of sending everything to only one person?
Yes, it is possible – configure your approval process to accept the first approval via manual. Then in the flow use the decision element to beach based in amount and submit the record to support.
Please explain how can we assign approval to more than one approvers.
i.e We are updating record (ProcessInstanceWorkItem) with new approver , can we create one or more record (ProcessInstanceWorkItem) for multiple approvers ?