I have to use an Autolaunched Flow to automate the following task:

  1. Retrieve all the certain object's records which meet a certain criteria.
  2. If the size of the collection is 1 - assign some field values from the only record to the one which originally triggered the flow.

The only idea I came up with:

  1. Retrieve records to the collection variable.
  2. Iterate through this collection and with every loop count increment the sizeCounter (default set to 0) variable
  3. If the size variable equals to 1 - retrieve records again, but now put only "the first one" to the new, single record variable

Looks like a very poor solution but I can't find any alternative. Is anyone aware of a better way to solve this problem?

  • Why would you want to retrieve all the object records and not only the record which triggered in first place?
    – user28452
    Jun 13, 2019 at 13:20
  • Because I need to know that there's only one record meeting filter's criteria. Jun 13, 2019 at 16:48

2 Answers 2


As of Spring '20, you can use the GetFirst action in the CollectionProcessors package.

  • The above package would not install in my sandbox. I'm waiting for SF Support to find out what the error message is. Mar 25, 2020 at 19:34
  • Brian, try taking the install url above and replacing 'login' with 'test' Mar 26, 2020 at 0:19
  • I'm aware of that; it was something else. In any case, I was able to get the first element in a collection variable by using loops. Not very user-friendly but it gets the job done. Apr 10, 2020 at 18:22
  • Note that the GetFirst action will not work on string collections, only object record collections.
    – Garywoo
    Jul 13, 2021 at 19:23

As an alternative to the accepted answer, since the addition of native Collection Filters in Flow (as of Spring '22) you can do the following:

  1. Filter your collection so that only 1 result should be returned (if more than 1 result is returned, this solution will still only return a single collection entry)
  2. Create a Loop element that iterates on the new Filtered Collection
  3. In the For Each path assign the Current Item from the Loop to a new variable
  4. Use a Connector to exit the Loop to the next Element in the Flow right after the assignment

It looks something like this: enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .