Using the IN operator

Hey Everyone,

Happy Saturday!

Have you ever needed to find and update multiple child records with flow, starting off using multiple parent records?

For example, lets say you have a screen flow that shows users a list of accounts:

And you have two requirements from your business.

First, allow users to pick as many accounts as they like from the list.

Second, when the user hits “Next” on the screen flow, close all the cases related to each of the accounts chosen by the user.

How would you tackle this?

The answer is by using the IN operator.

This operator shows up in the pink data elements (like Get and Update records).

Once we know how the IN operator works, it lets us find and update the specific child records we want, using just the parent record IDs.

In this scenario, we are finding cases to update using just the parent account IDs, but the process will work any similar situation.

The first step to using the IN operator is to create a Text variable that accepts multiple values (a collection).

The second step is to pass all the parent record IDs in to the collection.

In this scenario, those are the accounts selected by the end user.

You can see above I created a Text Variable that accepts multiple values (a collection).

Then I set up a loop, shown below, to loop through each item selected by the user in the data table.

And add those account IDs to the text collection, one by one.

Which ultimately looks like this:

The point of all this work is to put every account ID in one long list, and tell Salesforce (by using a pink data element like the Get records element)

“Hey go find me every case that’s related to one of these accounts.”

And now you have all your cases in one collection!

You could loop through them to perform different actions if you wanted. Such as creating tasks for overdue cases, or notifying users about escalated cases.

Or, as in this scenario, we could use an update records element to update all those cases immediately.

The entire flow looks like this:

And you can see, when we run the flow in the debugger, that it successfully updates multiple cases:

Figuring this out the first time was a game changer for me.

I helped another client with this problem this week, and so thought I’d share it with you too.

Hope you find it useful at some point!

Best,

Nick

Keep reading

See all posts →

Salesforce Saturdays

Join 1,036 Salesforce pros getting one 10-minute tip on Salesforce tech or career growth every Saturday.