One of the big asks for Flow is to be able to have the ability to get Records where the Id is IN a list of Ids. There is an idea on the idea exchange which, at the time of writing this post, has 6,330 points. This is a hot request as many times in the Flow you know the Ids and can create a list of Ids, but you can’t Query based on that list of Ids. Until now.

With Flow Components Winter ’21 release, there is now the ability to query Records where the Id is IN a collection. There is an Apex Action, Get Records WHERE Id is IN List, that makes this possible. In the Flow Apex Action, there are a few pieces to set to ensure you can use the Action. First, the Action needs to know what the Object is for the list of Records that will be returned. When you click into the box, it will give you a list of objects to select from. In the example below, the Contact object was selected. Next, you need to include the Text Collection Variable. This does need to be a Text Collection variable of Ids only. If you’d like to select records from a Related List, check out the Related List Button to Send Records to Flow post. Finally, click the Manually Assign Variables (Advanced) checkbox to set the Record Collection Variable. This should be a variable, type Record, where you are selecting the same Object as the Object that you’re Querying. In the example below, since the Contact object is being queried, the record collection variable is for the Contact object. Make sure that you select the Allow multiple values (collection) checkbox on your variable. The query will return all available fields that the User has access to for the object that you select.


  1. Hi Rich, I was hoping to find a solution re: WHERE Id IN collection. However, I could not generate such text collection with Ids retrieved by a Get Records operation (that’s always a record collection, not a text collection. Did I miss something there? Use Case: Get Account Records for the Account Ids that I have retrieved through a Get Debtor Records (custom object incl. lookup to Account). Currently I am trying to solve this by a loop within a loop, which always breaks at governor limits. Best regards, Ralf

    1. Hi Ralf,

      If you are doing a query, then you can loop through it and add it to the collection, you shouldn’t have to have a loop within a loop. Alternatively, if it is something that you would be able to select from a related list ahead of time, check out our post on the related list button, as that sends into Flow exactly what is needed for the WHERE Id IN Collection. I hope that helps, let me know how it goes!


      1. Ok, let’s dig deeper into the use case:

        I need to put certain Contacts into a Campaign. These Contacts are defined as follows: Look for Debtors of certain criteria, lookup their Account and from there, lookup the Account’s Primary Contact (a Contact lookup field on Account). SOQL is very easy on that: SELECT Account__r.PrimaryContact__c from Debtor__c WHERE…

        My approach without flow components was to get selected Debtors, get selected Accounts and then loop through all Account records to check whether Id is the same as for any of the Debtors’ Accounts and create Campaign Members for all Primary Contacts of the matching Account. iThis was the loop-within-a-loop.

        With your flow component, I would expect to be able to use the Get Debtors collection variable (that contains the Account IDs) for using it as search list in terms of an IN condition, but how would I get a text collection variable of Debtor__r.Account__c?

        Besides that, I could easily put a formula field Account__r.PrimaryContact__c on Debtor and just Get the Debtors for retrieving the relevant Contact Ids, but this seems to be yet-another-redundant-formula-field.

      2. Hi Ralf,

        With Flow, you can query the debtor record and loop through it without having to do another query on account. Flow allows you after the query (if you use automatically store all fields) to do something like, assign a campaign member contact Id using debtor.account.primarycontact, without having to continue to query each level. This is native in flow as of a few releases ago. So although you aren’t specifying it in the query, flow sees you’re using it later in the flow, and queries it. It does have a little bit of trouble if you’re using it in a formula only, but in an assignment or decision it works well.

        The query we have in Flow Components is if you have a list of IDs that you want to get records for, you can query based on the main Id being in the list. So, an example might be, get debtors, loop through and if something on the account record means the contact needs to get added to the list, add the contact Id to a collection variable. Then after you have all those contacts, you can query them together in a single query and do something with it, perhaps show them to a user in a table, loop through those for something else, etc. Of course, my favorite example is using this with a related list as we can send the IDs of the selected records in the related list to the flow as the collection variable we need.

        Let me know if that helps!


      3. This makes totally sense. So actually, it is about collecting Ids through e.g. a loop and adding these subsequently to the text collecting variable for later reference through the WHERE … IN logic.

        I have in parallel found out that currently, my use case is completely supported by SF flow standards (querying the debtors and then looping through them for collecting the relevant accounts and contacts) and doesn’t need your tools. However, I will keep it for future use cases.

        Thanks for giving the chance for exchanging thoughts about this!

  2. Hi,
    I really want to use this Get Records Where ID….action

    I can find it?
    WE are on Summer 21 and I cant find the action, or even a class

    I know i am missing a “preStep” somewhere

    I have a flow collection of IDs, and would like to invoke this action.

    Please advise

  3. That is a pretty need extension – of course there is always something to wish for.
    Like being able to select a field OTHER than ID in the target object! For example I want to collect files from several contacts. So I have a list of contact ID’s and now I would like to query Content Links for Where LinkedEntityId is in that set of contacts ..

    Just saying!

    Thanks for the great ‘plugin’

    1. You’re welcome! Something like that might come one day, I used to have working code for that a while back, I believe I actually presented it at Dreamforce a few years ago. This specifically works with the related list button to select records from a related list and send them into a flow, this is how you get the list of the records since related list buttons only give us the ids. Thanks for the feedback and suggestions, we’ll definitely keep it in mind.

  4. It’s not clear from your article that your managed package is required. It would be good for you to update the article to clarify that.

Leave a Reply to Rich EnglhardCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.