top of page

Workaround for IN clause in Flows – Part 1

May 7, 2019
2 min read

Howdy folks! 😀

In this article, we shall see how we can set up an equivalent for IN clause(“Select… where IN… “; SOQL, ring a bell?) in a flow.

Currently, we do not have any out of the box equivalent for IN clause in flows. So generally we end up doing queries inside a loop. But we can work our way around it.

Use Case:

Let us assume that we have a list of Account records and we have to get(query) all the child contacts associated with those Account records.

Logic:

In a nutshell, the idea is to get the IDs of all the Account records in a string. Query all the contacts from the database and then loop through all the contacts and compare the ID of the contact’s Account with the string using CONTAINS operator.

Let’s roll!

Step 1: Like always we kick off by creating some variables in our flow.

Step 2: For our use case, we shall assume that we have a list of accounts whose name starts with ‘U’. So to set that up, we will use the Get Records element to get the list of account names starting with ‘U’.

Step 3: Now that we have our list of Accounts, the real work begins. So now we loop over the Account list, using the Loop element and add the Account IDs to a string variable separated by ‘;’ using the Assignment element.

Step 4: The next step is to query all all the contact records, using Get Records element and loop over them using Loop element as shown.

Step 5: Inside the loop, using a Decision element, we will check if the string containing all the Account IDs contains the Contact’s record ID. If yes, then we add the that contact’s name and finally print that list on a flow screen.

Final Flow:

Let’s see it in action!

Things to know

This approach is quite vulnerable to errors. For example, what if you have more than 50,000 records, you will get an query exception. Also, there is a high probability of hitting the max. flow execute limit i.e. 2000.

Thank you! 🙂

 
 
 

Comments


bottom of page