Easy “IN” Filters in Flow with the FilterCollection Flow Action

Intro Video

SOQL provides a useful IN operator that filters the query on a specific set of values:

credit: https://www.salesforcetutorial.com/soql-in-operator/

You currently can’t do this directly in the Flow Builder Get Records element, but you can install this FilterCollection Flow Action to provide the capability.

Out of the box, this action is set up to support standard objects: Contact, Account, Opportunity, Lead, Product, Case. You can easily modify it in Apex to support additional objects of your choice (see customization, below).



For our example, we want to query for all accounts that have an Industry that’s IN Banking or Chemicals. We expect to get back three of these four accounts:

Configure this Action by passing three pieces of information:

  1. A collection of SObjects. You can pick from the supported list. At this moment, 5 standard objects are supported. You can only pass in a single collection of SObjects. Leave the other inputs blank.
  2. ‘filterField’: The name of the field on your SObject that you want to filter on. In our example we’ll set this to Industry.
  3. The target values. These are equivalent to ‘Rose’ and ‘Sean’ in the above example image. In our example, we’ll pass in Banking and Chemicals. You can pass the values in either as a single comma-separated list in the targetValuesCSVString input, or as a collection of strings in the targetValuesStringCollection (don’t use both at the same time).

Here’s an example of a properly configured set of inputs:

This action will return a corresponding collection of filtered objects. Make sure you create a collection variable of the appropriate Record type and map it in the Store Output Values tab.

Optional: Customization

The following information is for advanced Flow users and discusses how this action can be modified to support additional types of objects. A current limitation in Flow makes it so that Apex Actions have to add specific code for each specific sObject they want to support (it’s on the roadmap to eliminate this limitation). So the bad news is that only 5 common standard objects are currently supported in FilterCollection.

The good news, though, is that it’s easy to add support for additional standard objects and custom objects.

To add support for an additional object, you have to add code in four places. First, add an input variable to the Requests inner class and an output variable to the Results inner class:

To process the input collection, add a code block based on the five lines immediately below. This has the effect of casting (transforming) your specific SObject collection to a general SObject collection. Then at the end, add a when clause to the switch statement to cast the general filtered-down collection back to the specific SObject type that Flow needs:

If you do add more standard objects, please consider making a pull request to the source code so everyone can benefit from your work!

Source Code