Getting Started with Salesforce Flow – Part 49 (Don’t Let Pending Approval Requests Linger – Reassign!)

Getting Started with Salesforce Flow – Part 49 (Don’t Let Pending Approval Requests Linger – Reassign!)

Last Updated on January 4, 2021 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?! 

  1. Getting Started with Salesforce Flow – Part 43 (Dynamic Approval Routing in Salesforce)
  2. Getting Started with Salesforce Flow – Part 31 (Auto Submit Record into Approval Process with Flow)
  3. Getting Started with Process Builder – Part 98 (What say? Send an Opportunity Approval Request to a Queue? Really?)
  4. 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:

  1. Define flow properties for scheduled-triggered flow
  2. Add a formula to calculate 6 days before today
  3. Add a decision element to check, if the step is waiting for approval for 6 or more days 
  4. Add a get record element to find the role CFO id
  5. Add a get record element to find CFO user-id
  6. Add an assignment element to assign the CFO user id to actor id
  7. Add an update records element to update the actor id for pending approval request 

Step 1: Salesforce Flow – Define Flow Properties 

  1. Click Setup.
  2. In the Quick Find box, type Flows.
  3. Select Flows then click on the New Flow.
  4. Select the Schedule-Triggered Flow option and click on Next and configure the flow as follows: 
    1. How do you want to start building: Freeform
    2. Set Schedule
      1. Start Date: Dec 25, 2020
      2. Start Time: 8:00 AM
      3. Frequency: Daily
      4. Click Done.
    3. Select Object: ProcessInstanceWorkItem
  5. Select None-Run Flow For All Approval Requests.
  6. Click Done.

Step 2: Salesforce Flow – Create a Formula to Calculate 6 Days Before Today

  1. Under Toolbox, select Manager, then click New Resource to create a formula to calculate 6 days before today. 
  2. Input the following information: 
    1. Resource Type: Formula
    2. API Name: forDT6DaysBeforeToday
    3. Data Type: Number
    4. Decimal Places: 0
    5. Formula: {!$Flow.CurrentDateTime} – 6
  3. 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

  1. Under Toolbox, select Element
  2. Drag-and-drop Decision element onto the Flow designer. 
  3. Enter a name in the Label field; the API Name will auto-populate.
  4. Under Outcome Details, enter the Label the API Name will auto-populate.
  5. Condition Requirements to Execute OutcomeAll Conditions Are Met (AND)
    1. Row 1:
      1. Resource: {!$Record.SystemModstamp}
      2. Operator: Less Than or Equal
      3. Value: {!forDT6DaysBeforeToday}
  6. 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. 

  1. Under Toolbox, select Element
  2. Drag-and-drop Get Records element onto the Flow designer. 
  3. Enter a name in the Label field; the API Name will auto-populate.
  4. Select the UserRole object from the dropdown list.
  5. Select All Conditions Are Met (AND)
  6. Set Filter Conditions
    1. Row 1:
      1. Field: DeveloperName
      2. Operator: Equals
      3. Value: CFO
  7. How Many Records to Store:
    1. select Only the first record
  8. How to Store Record Data:
    1. Choose the option to Automatically store all fields
  9. 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. 

  1. Under Toolbox, select Element
  2. Drag-and-drop Get Records element onto the Flow designer. 
  3. Enter a name in the Label field; the API Name will auto-populate.
  4. Select the User object from the dropdown list.
  5. Select All Conditions Are Met (AND)
  6. Set Filter Conditions
    1. Row 1:
      1. Field: UserRoleId
      2. Operator: Equals
      3. Value: {!CFO_Role_Id.Id}
  7. How Many Records to Store:
    1. select Only the first record
  8. How to Store Record Data:
    1. Choose the option to Automatically store all fields
  9. Click Done.

Step 6: Salesforce Flow – Using Assignment Element to Assign CFO User Id to Actor Id

  1. Under Toolbox, select Element
  2. Drag-and-drop Assignment element onto the Flow designer. 
  3. Enter a name in the Label field; the API Name will auto-populate.
  4. Set Variable Values
    1. Row 1:
      1. Field: {!$Record.ActorId}
      2. Operator: Equals
      3. Value: {!CFO_User_Id.Id}
  5. Click Done.

Step 7: Salesforce Flow – Using Update Records Element to Update the Actor Id

  1. Under Toolbox, select Element
  2. Drag-and-drop the Update Records element onto the Flow designer. 
  3. Enter a name in the Label field; the API Name will auto-populate.
  4. 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.
  5. Map Select Record(s) to Update:
    1. Record or Record Collection: {!$Record}
  6. Click Done.

In the end, Warren’s Flow will look like the following screenshot:

Once everything looks good, perform the steps below: 

  1. Click Save.
  2. Enter Flow Label the API Name will auto-populate.
  3. Click Show Advanced.
  4. Type: Schedule-Triggered Flow
  5. API Version for Running the Flow: 51
  6. Interview Label: Reassign Pending Approval Requests {!$Flow.CurrentDateTime}
  7. 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: 

  1. Navigate to Setup (Gear Icon) | Environments | Jobs | Scheduled Jobs.
  2. Now look for your Scheduled Flow displaying information as shown in the following screenshot:
  3. 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.  

  1. 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
  2. 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 @automationchampusing #AutomationChampion. 

Have feedback, suggestions for posts, or need more information about Salesforce online training offered by me? Say hello, and leave a message!

One thought on “Getting Started with Salesforce Flow – Part 49 (Don’t Let Pending Approval Requests Linger – Reassign!)

  1. 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 ?

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.