Easiest Way to Find if a Record Is in the Approval Process Using Salesforce Flow

Easiest Way to Find if a Record Is in the Approval Process Using Salesforce Flow

Last Updated on February 13, 2024 by Rakesh Gupta

Big Idea or Enduring Question:

  • How Do You Find Out If a Record Is in the Approval Process When Using Salesforce Flow?

Objectives:

After reading this blog, you’ll be able to:

  1. Work with the ProcessInstance object.
  2. Find out if a record has pending approval without using any code.
  3. Create a reusable process that can be called from other flows.
  4. And much more.

👉 Previously, I’ve penned several posts on the Salesforce Flow and Approval Process. Why not check them out while you are at it?!

  1. Auto Submit Record into Approval Process with Flow
  2. Dynamic Approval Routing in Salesforce
  3. Don’t Let Pending Approval Requests Linger – Reassign!
  4. What say? Send an Opportunity Approval Request to a Queue? Really?

Business Use case

Benjamin Moore is a Salesforce Administrator at Gurukul On Cloud (GoC). While working on a flow, he wants to create a reusable flow that takes a record ID as input and returns true/false, based on whether a record is in the approval process or not.

Automation Champion Approach (I-do):

While this can be solved using various methods, such as Invocable Apex, we will use an Autolaunched Flow (No Trigger) to solve it.

Before proceeding ahead, you have to understand the ProcessInstance object. It represents an instance of a single, end-to-end approval process. Use this and the node, step, and workitem process instance objects to create approval history reports.

Field Name Details
ProcessDefinitionId The Id of this approval process instance.
TargetObjectId The Id of the object affected by this approval process instance.
Status The status of this approval process instance, for example Started, Pending, or Approved.

Before discussing the solution, let me show you a diagram of the process at a high level. Please spend a few minutes going through the following Flow diagram to understand it.

Let’s begin building this automation process.

Guided Practice (We-do):

There are 6 steps to solve Benjamin’s business requirement using Autolaunched Flow. We must:

  1. Define flow properties for the autolaunched flow.
  2. Create a Text Variable to store the record ID.
  3. Create a Boolean Variable to store the flow outcomes.
  4. Add a Get Record element to find the pending approval for a given record.
  5. Add a Decision element to check if the pending approval was found or not.
  6. Add an Assignment element to set the Boolean variable created in step #3 to True.

Step 1: 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 Autolaunched Flow (No Trigger) option.
  5. Click on Create.

Step 2: Add a Text Variable to Store the Record Id

  1. Under Toolbox, select Managerthen click New Resource to store the record Id. 
  2. Input the following information: 
    1. ResourceTypeVariable
    2. API Name: varT_RecordId
    3. Data TypeText
    4. Default Value: {!$GlobalConstant.EmptyString}
    5. Check Available for Input
    6. Check Available for Output
  3. Click Done.

Step 3: Add a Boolean Variable Variable to Store the Flow Outcomes 

  1. Under Toolbox, select Managerthen click New Resource to store the flow outcomes. 
  2. Input the following information: 
    1. ResourceTypeVariable
    2. API Name: varB_IsInApprovalProcess
    3. Data TypeBoolean
    4. Default Value: {!$GlobalConstant.False}
    5. Check Available for Input
    6. Check Available for Output
  3. Click Done.

Step 4: Adding a Get Record Element to Find the Pending Approval for a Given Record

The next step is to use the Get Records element to find the pending approval for a given record.

  1. On Flow Designer, Click on the +icon and select the Get Records element.
  2. Enter a name in the Label field; the API Name will auto-populate.
  3. Select the ProcessInstance object from the dropdown list.
  4. Select All Conditions Are Met (AND)
  5. Set Filter Conditions
    1. Row 1:
      1. Field: TargetObjectId
      2. Operator: Equals
      3. Value: {!varT_RecordId}
    2. Click Add Condition
    3. Row 2:
      1. Field: Status
      2. Operator: Equals
      3. Value: Pending
  6. How Many Records to Store:
    1. select Only the first record
  7. How to Store Record Data:
    1. Choose the option to Automatically store all fields
  8. Click the X at the top to save your changes.

Step 5: Using Decision Element to Check If the Pending Approval Was Found or Not

Now, we will use the Decision element to check if the previous Get Records element returns pending approval for a given record. 

  1. On Flow Designer, click on the +icon and select the Decision element.
  2. Enter a name in the Label field; the API Name will auto-populate.
  3. Under Outcome Details, enter the Label the API Name will auto-populate.
  4. Condition Requirements to Execute OutcomeAll Conditions Are Met (AND)
    1. Row 1:
      1. Resource: {!Get_ProcessInstance}
      2. Operator: Is Null 
      3. Value: {!$GlobalConstant.False}
  5. When to Execute Outcome: If the condition requirements are met.
  6. Click Done.

Step 6: Adding an Assignment Element to Add the Record Variable to Record Collection Variable

  1. On Flow Designer, below the Decision node, click on the +icon and select the Assignment element. 
  2. Enter a name in the Label the API Name will auto-populate.
  3. Set Variable Values
    1. Row 1:
      1. Field: {!varB_isInApprovalProcess}
      2. Operator: Equals
      3. Value: {!$GlobalConstant.True}
  4. Click Done.

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

Once everything looks good, perform the steps below: 

  1. Click Save.
  2. Enter Flow Label (Find Pending Approval for a Record) the API Name will auto-populate.
  3. API Version for Running the Flow: 59
  4. Click Save.

Proof of Concept

Going forward, you can use the autolaunched flow we created with any flow that supports it. Find out if a record has pending approval by simply passing a record ID. The autolaunched flow will return true or false based on the flow’s outcomes.

If a record has pending approval, then the autolaunched flow will pass true for the variable varB_isInApprovalProcess, as shown below. 

Formative Assessment:

I want to hear from you!

What is one thing you learned from this post? How do you envision applying this new knowledge in the real world? Feel free to share in the comments below.

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

Preferred Timing(required)

2 thoughts on “Easiest Way to Find if a Record Is in the Approval Process Using Salesforce Flow

  1. A quick question to this if I may:
    If I understand it correctly then it checks just one record. How does it go trough all the records which should be marked?
    Many thanks for the interesting article and a small feedback.

Leave a Reply

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

Discover more from Automation Champion

Subscribe now to keep reading and get access to the full archive.

Continue reading