Flow: How To Use In / Not In Operators

I believe many have been looking forward to the In / Not In operators available in Winter’23 release. This helps us build a flow that can be more efficient than ever! However, it is not perfect yet because it does not support the record collections yet, so we have to implement some workaround in order to use them. Let’s take a look on how to achieve so!


To get a full list of Contacts whose Account rating is marked as Hot.

The official release note has explained the solution very clearly. Since the In/Not In operator only support primitive data type, we will have to build a loop to store all the Account Id into a text collection. Then we will be able to use this collection together with the In/Not In operator. In this example, I will only demonstrate the In operator. Just keep in mind that the Not In operator is the opposite of using In operator.

Flow Chart (deactivate last login date)

Partial Flow Chart – Can be incorporated into your own solution

Flow Problem Statement.png
Steps (deactivate last login date)

Is This Helpful? Check Out Flow Use Cases Or Write Us One!

Subscribe
Notify of
guest

5 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Neil

Thanks, Melody. It’s exciting to see Flow get new functionality. But it also makes you appreciate the efficiency of a well-written SOQL query.

SELECT Id, Name, AccountId FROM Contact WHERE Account.Rating = 'Hot'
Gustavo Seluja

I initially thought these new additions would allow us the enter values as when writing a SOQL query. Can you provide a use case, where before it was not possible, and now it is because of this? Thanks Melody, and welcome back (looks like they’re keeping you busy 😁 )

Last edited 2 years ago by Gustavo Seluja
Neil

I don’t believe using In or Not In allows Flow Builder to do anything it couldn’t do in the past but it does add efficiency. In the example above, the flow can be done without using In but you would need an additional loop (loop within a loop) and a collection resource to achieve the same result. Once In can be used in record collections, its true purpose will be realized — just like a bind variable in a SOQL query:

SELECT Id, Name, AccountId FROM Contact WHERE AccountId IN :hotAccounts
Ian Jamieson

Thank you. This is very useful. I do need to spend more time learning about Flows.

Paul

Have you encountered the issue where this fails if there is only one record in the collection? Salesforce support is trying to tell me that you can only use the In operator if there is more than one record, but how would I know that ahead of time? This means any flow that uses the In operator needs to check to make sure the collection has more than one value and have an alternative path if it only has one.