Get Records IN Flow Action

Created by Eric Smith


This post was most recently updated on 7/1/22

Current Version 1.0.2


How many times have you wanted to do a Get Records in your Flow where the condition was that something be in a Collection of something else?

This idea on the Idea Exchange from over 7 years ago has over 16,500 points.

Flow: Support equivalent of SOQL “IN” condition in Record Filters

What are some of the use cases?

  • You have a collection of record Ids from some other process and you now want to Get all of the Records whose Ids are in that collection, such as getting all Parent records when you have a collection of Child records
  • You want to Get all of the Primary Contact Records whose Account has a past due balance.
  • You want to email all of the Users whose manager is one of the Regional VPs of Sales 
  • You want to update every Opportunity with any line items with a Product from a particular Product Family

Until now, your only option, using standard Flow components, was to follow a bad design pattern and perform a series of Get Records inside of a Loop.  Not only is this a bad practice, oftentimes you could hit a limit of too many SOQL queries before your Flow could even finish.

With my new Get Records IN invocable Flow Action, you can now do a Get Records on an Object where the value of a field in that Object is IN a collection of other values.

To make it easier to implement and to be useful in multiple scenarios, you can specify your Source Collection in one of three different ways.

  1. A single Delimited String of values
  2. A flow Collection Variable
  3. A Collection of Records where you identify the Field to use for the comparison

Similar to the standard Get Records component, you can specify your output to “Automatically store all fields” or “Choose fields and let Salesforce do the rest”


Custom Property Editor

You configure this component using the supplied Custom Property Editor.

(1) Select the Object you want to Get the Records from

  • If the required Object doesn’t appear in the list, check the “Display ALL Objects for Selection” box to see all Salesforce Standard and Custom objects

(2) Select the Field from that Object that will be compared with the values in the specified Collection

  • This will default to the Id field

(3) Select the method you want to use to identify the source of the collection values

  • Delimited String
    • Select the Flow variable that has your string
    • Select the delimiter character (default is a comma)
  • Text Collection
    • Select the Flow collection variable that has your values
  • Record Collection
    • Select the type of Object whose collection of records will be used
    • Select the Flow Record Collection variable to extract the values from
    • Select the Field whose values will be used for the collection

(4) Select what fields you want to store in the Output records

  • If you specify “Choose fields …”, you can then select the individual fields to include in the Output records.  Note: Id will always be included by default.
  • When choosing your output fields, the selected fields will show below the input selection. If more fields are selected than will show on a single line, you can temporarily expand the display to show all fields and then collapse it again by clicking on the prompts.

Restrictions

Only certain types of fields that can be represented as a String can be used for the target field and the collection fields.  These are Lookup, Email, Phone, Picklist, Multi-Picklist, URL, Text and some TextArea fields.  If you want to use other types of fields, create a formula field on your object that will convert the value to a string.


Sample Use Case

Watch this video to see a simple example of how this action can be used in a Flow in place of a Get Records inside of a Loop.


Notes

  • I want to give special thanks to David Fromstein for the use of his new Object and Field Selector components in the Custom Property Editor
  • Future enhancements may include the ability to specify additional filter criteria and sorting the output.  For now you can use the standard Filter and Sort components in your Flow after this action to further refine your results.
  • This version of the component is not bulkified to support running in a Record Triggered Flow. If you need a partially bulkified solution, please consider solo-1234’s GetRecordsInCollection Apex action. https://github.com/solo-1234/GetRecordsInCollection

Installation

Step 1

This component requires that you first install or upgrade the Flow Base Packs

  • FlowActionsBasePack Version 3.0.0 or later
  • FlowScreenComponentsBasePack Version 3.0.7 or later

Step 2

Install the GetRecordsIN package

Production or Developer Version 1.0.2

Sandbox Version 1.0.2

Step 3

All users running a Flow that uses this component will need access to the following Apex Classes in their Profile or an assigned Permission Set

  • GetRecordsIn
  • ObjectFieldSelectorController

Release Notes

6/26/22 – Eric Smith – v1.0.2

First Public Release


Previous Versions

Production or Developer Version 1.0.2

Sandbox Version 1.0.2


View Source

Source Code