Collection Filter, Sort, and Transform
Key Takeaway
Collection Filter outputs a new collection and leaves the source collection unchanged. Collection Sort reorders the collection you select, and can trim it, in place. Transform can't filter or sort, so to turn the top N matching records into records of another object, run Collection Filter, then Collection Sort, then Transform.
Collection Filter, Collection Sort, and Transform are Flow Builder elements that reshape a collection the flow already holds. Collection Filter keeps only the items that meet your criteria. Collection Sort puts the items in order and can cut the collection down to a set number of items. Transform maps source data into a new target structure, such as a record collection of another object or a text collection of record IDs. Later steps must use the right collection, so it matters which elements create a new collection and which change the existing one.
Collection Filter makes a new collection
Collection Filter applies criteria to a collection and outputs a new collection that contains only the items that meet the criteria. The source collection doesn't change, so the flow can still use the original, unfiltered collection in later steps. The output collection is null until its Collection Filter element runs.
You can filter any collection in Flow Builder, including these kinds:
- Collection variables that contain single values, such as a text collection
- Collection variables that contain records
- Apex-defined collection variables
A screen flow asks an event planner to enter the cities on a tour and stores them in a text collection: Berlin, Madrid, TBD, and Oslo. A Collection Filter element with a condition that leaves out "TBD" outputs a new collection that holds Berlin, Madrid, and Oslo. The flow uses that new collection to build the confirmed schedule. A later step still uses the original text collection, which holds all four values, to list every stop the planner entered.
The output collection is named after the element's API name. For example, a Collection Filter element named FilterLeads outputs a collection called "Leads from FilterLeads".
The element also creates a single variable called CurrentItem_FilterLeads, which acts as a loop variable for the element's input collection. You can reference CurrentItem_FilterLeads in a formula. If you delete the Collection Filter element, the CurrentItem_FilterLeads variable stays in the flow. You can safely delete that single variable after you remove the element.