Collection Processors for Flow (Sort, Filter, Find, Join, Map, and more)
This package contains new Flow actions that are designed to manipulate any SObject or collection of SObjects. This means that in one Flow you might use them with a collection of Accounts and in another flow a collection of Leads.
This Post was most recently updated on: 5/16/23
Current Version: 3.1.1
- Added new Collection Action: Return First N Records
Note: If you are defining record collection variables in your flow and do not assign any value to them, many of these actions will fail with a “Missing required input parameter” when called from the flow. If there is a chance that your flow logic could bypass any assignment to the variable, be sure to add an Assignment element setting the collection variable to nothing before calling the action.

Install Current Version
Installation links at the bottom of this page.
Updates
1/12/22 – Upsert Collections updated to support JSON inputs
10/3/21 – Eric Smith – Added support to Map Collection for mapping numeric fields
6/21/21: Now includes a Permission Set for all Apex Classes in the Collection (USF Flow Action – Collection Actions)
5/23/21: CollectionCalculate
4/22/21: Dedupe Record Collection
2/3/21: Compare Record Collections
Notes on Dynamic Inputs
Keep in mind that you can insert mergefields as dynamic inputs in these actions. A mergefield takes the form of a reference name surrounded by braces and an exlamation point: {!myUpstreamVar}. So for example, you can use Map Collection like this:
“Rating” : “Warm”, “Industry” : “Banking“
or like this:
“Rating” : “Warm”, “Industry” : “{!myUpstreamVar}“
To get the syntax right, use this rule: Flow Builder will replace everything between braces before passing the inputs to the invocable action.
Add or Insert Record
Takes as input a collection of records and a single record, and an optional index value. Returns the combined collection. If the index value is specified and is less than the length of the inputCollection, the
Inputs
List<SObject> inputCollection;
SObject inputRecord
Integer index
Outputs
List<SObject> outputCollection;
Collection Calculate
Allows Add, Multply, and Average aggregate operations across a collection of records.
Copy Collection
Takes as input a collection of records and returns the collection as output, allowing a new variable or reference to have the same value
Inputs
List<SObject> inputCollection;
Outputs
List<SObject> outputCollection;
Count Records And Fields
Takes a collection of records and returns a count. Optionally also takes a field name and a field value, and then also counts the number of records that have that particular value for that particular field. Returns both the number of matches and the total number of records. Added in V
Inputs
List<SObject> inputCollection;
String fieldName;
String fieldValue;
Outputs
Integer totalNumber
Integer matchedNumber
String errors
Dedupe Record Collection
Returns a set of de-duped records based on the field you specify. More Information
DeepClone
Clones a record and one or more sets of its child related records. More Information
Extract Strings From Collection (with Dedupe)
Takes a collection and a field name, and returns a list of strings reflecting the values of those fields for the records. For example, if you pass in a list of Contacts and a fieldName of “Id”, you’ll get back a list of recordIds for the contacts.
Features
- Extract a text collection or comma-separated string of any field for each record in a Record Collection
- Particularly useful for Ids, Picklists, Multi-select picklists
- Optionally de-dupe the values returned from all of the records.
- Supports Multi-select picklists across all records in the collection
- Useful when paired with the new AddQuotesToFields and ExecuteSOQL actions to pass in a set of strings wrapped in quotes
- Ex.
Select Name, Email from Contact where Id in (‘003023044333sDl’, ‘003023044333sKF’)
- inputRecordCollection
- List of records to extract field values from
- fieldAPIName;
- API Name of the field you want returned
- dedupeValues;
- If true only unique values will be returned. The default value is true
- fieldValueCollection
- Extracted fields in a text collection
- fieldValueString;
- Extracted fields in a comma-separated text variable
Filter Collection
Filters a collection against a formula string which can be created by an included Expression Builder Flow Screen Component.
Inputs
List<SObject> inputCollection;
String formula;
Outputs
String errors;
List<SObject> outputCollection;
Details
For each member of the inputCollection, this action will evaluate the provided formula and add the member to the outputCollection if the formula is true.
The formula must be a string that can be processed by the Salesforce formula engine. The actual engine that evaluates this string is written in Apex and is included in the Collection Processors package.
It will use the recordId of the current member as context, replacing expressions in the formula string of the form $Record.fieldname. For example, if the formula is ‘$Record.Age__c > 21’ and the input Collection is a collection of Student__c, the evaluator will do the following:
Loop through the collection of Student records. For each record:
- use its ID and retrieve the record
- retrieve the values of any fields present in the formula string
- use the formula evaluator to evaluate the formula
- If the formula evaluates to true, add the current record to the output collection
Also see ‘Notes on Dynamic Inputs‘ at the top of this post.
Find Record in Collection
Returns all records from the inputCollection that have a field with name targetField that has a value of targetValue. Pass in the name of the object in targetObject (for example, if the inputCollection is a List of Contacts, set targetObject to Contact. There’s probably a way to determine this automatically but it’s not implemented in the action at this time). If there’s just a single result, the result is returned as singleOutputMember. Otherwise it’s returned as multipleOutputMembers. Version 1.20+: MultipleOutputMembers returns null if there are no results
Inputs
List<SObject> inputCollection;
String targetObject
String targetField
String targetValue
Outputs
SObject singleOutputMember;
List<SObject> multipleOutputMembers
Find Common and Uncommon Records
Compares & Contrats two record collections – even different sObject Types!
Generate Collection Report
Given a collection and a comma-separated list of field names, generates a string that includes all of the field values for every member of the collection. There are now two modes you can use. displayMode ‘simple’ simply throws the information out in simple groups. Useful for some debugging. displayMode ‘table’ generates HTML table markup that’s great for insertion into emails:

For full information on this action, see this post.
Inputs
List<SObject> inputCollection; | ||
String shownFields | a comma-separated list of the fields you want to show in the table. Make sure to use the full api names, including ‘__c’ for custom fields. | |
displayMode | ‘simple’ or ‘table’. defaults to simple | |
tableStyleString | will be inserted into the table html as a style attribute: <table style=”[tableStyleString]”> | |
headerStyleString | will be inserted into the <th> tags as a style attribute | |
rowStyleString | will be inserted into individual row tags (<tr>) as a style attribute | |
showHeader | Boolean |
Outputs
String reportString
Get Child Collection
Takes a record and returns a specified collection of child records related to the input record.
Pass in either a record or a recordID (as a string), but not both. Specify the childRelationshipName, which should be the name of the child Object. Example. If you have an Opportunity and want to retrieve all of the OpportunityContactRoles associated with the input, specify a childRelationshipName of OpportunityContactRole. Note that this should also be specified as the Output Collection.
In childRecordFieldsCSV, specify the fields you want returned as a comma-delimited string. Example: Id,Name
For more information, see https://unofficialsf.com/automate-junction-updates-with-getchildcollection-and-getlookupcollection/
Inputs
SObject inputRecord;
String inputRecordId;
String childRelationshipName;
String childRecordFieldsCSV;
Outputs
List<SObject> childCollection;
String errorText;
Get First
Returns the first member of the inputCollection. The inputCollection is not modified by this action. Make sure that the types of your inputCollection and outputMember match.
Inputs
List<SObject> inputCollection;
Outputs
SObject outputMember;
Get Lookup Collection
Takes a collection of records and the name of an object related via a Lookup, and returns a collection of objects.
Pass in either a collection of records or a collection of string record ID’s. Pass in the name of the related object. Example: You start with a collection of OpportunityContactRoles and you want to get the Contacts associated with your OpportunityContactRoles via the ContactId Lookup field. In this case you would set lookupObjectName to Contact.
In lookupRecordFieldsCSV, specify the fields you want returned as a comma-delimited string. Example: Id,Name
For more information, see https://unofficialsf.com/automate-junction-updates-with-getchildcollection-and-getlookupcollection/
Inputs
List<SObject> inputCollection;
List<String> inputIds;
String lookupRecordFieldsCSV;
String lookupObjectName;
Outputs
List<SObject> lookupCollection;
String errorText;
Get Records from Ids
The Collection Actions package of utility actions now has a new action that takes a collection of recordIds (i.e. a List of Strings) and returns the corresponding records. It carries out a SOQL query and obtains the fields that you specify by name. The records are returned both as a collection of records and a serialized (JSON) string.
Inputs
String objectName; | |
String fieldNames; | |
global List<String> inputIds; |
Outputs
List<SObject> records
String recordString
Join Collections
Takes two collections (of the same type, please!) and returns their union as a single collection.
Inputs
List<SObject> inputCollection1;
List<SObject> inputCollection2;
Outputs
List<SObject> outputCollection;
Map Collection
Takes a collection and a set of key value pairs. Example:
“Rating” : “Warm”, “Industry” : “Banking“
Goes through the collection and changes each field with a name matching the key to the specified value.
Note that dynamic inputs are supported: “Rating” : “Warm”, “Industry” : “{!myUpstreamVar}“. See above for more.
NOTE: this currently only works for string values.
Inputs
List<SObject> inputCollection;
String keyValuePairs;
Outputs
List<SObject> outputCollection;
String errors;
Map Collection supports mapping of Time fields.
Example:
The Account object has a time field, and you want to use that time field on every case created. You can get the time variable from the Account and convert that to a string by using a formula, TEXT(Account.TIME). Then use that formula variable to assign that to the case.
Remove Record from Collection
Takes a collection and an index integer. Uses the Apex List class remove method to remove the member of the collection at the index location.
Inputs
List<SObject> inputCollection;
Integer index;
Outputs
List<SObject> outputCollection;
Return First N Records from Collection
Takes a collection and an integer count and returns that count of records from the beginning of the collection. The entire collection will be returned if it doesn’t contain more records than the record count attribute.
Inputs
List<SObject> Input Collection;
Integer Record Count;
Outputs
List<SObject> Output Collection;
Integer Return Count;
Sort Collection
Takes a collection and a sortKeys string formatted as key value pairs (example:
“Name”:”ASC”,”Rating”:”Warm”
Known Issues:
1. Picklist fields are not supported.
2. If some of the records in your collection have a blank value for the field you’re sorting on, it will display the blank ones first no matter which direction you sort
3. The sorting priority is reversed from what I would have thought. It sorts first on the last key pair and then works backwards to the first.
Inputs
List<SObject> inputCollection;
String sortKeys;
Outputs
List<SObject> outputCollection;
Upsert
Upsert will either save or update a collection, depending on whether the collection already has ID’s
Attribute | Type |
inputCollection | List<SObject> |
inputRecord | SObject |
externalIdFieldName | String |
allOrNone | Boolean |
serializedRecordData | String. This should be a JSON string of key value pairs where the keys are the names of fields on a single object. for example: {‘AnnualRevenue’: ‘400000’, ‘Rating’: ‘Hot’} |
objectName | String. the name of the object that the serialized key value pairs belong to. Example ‘Case’. Only used to classify a passed in serializedRecordData |
For more info, see https://unofficialsf.com/create-or-update-with-the-new-upsertrecords-action/
Are you an Apex Developer?
Looking for a fun project? Consider one of these requested enhancements!
Name | What it Does | What should the inputs be? | What should the outputs be? | Suggested By | Discussion |
---|---|---|---|---|---|
EXAMPLE: Change Owner | Similar to Map Collection, but specialized for changing the owner field, and so a little easier to configure | Besides the input collection, a string that can either be a username or a user recordId | standard success vs. error return values | ||
Limit X | Similar to the First collection, but allow user to specify how many records to return from the collection. For example, they can pass an sobject collection and have up to X number of records returned in a new collection. | record collection | updated record collection | Chris Van der Merwe | |
IN Clause | Pass two object collections and do IN comparison | record collection, record collection2, field to check from record collection, field to compare against record collection 2 | record collection with records as result on IN Clause | Chris Van der Merwe | This comes up all the time, and is challenging for governor limits in flwo. |
Object API Name From Record Id | Pass in a record id of any object and get back the Object API Name | record id | Object Name | Patrick Loughran | The code for this is written if it makes sense to publish. |
Recaptcha Component | Use case | Available as a project! | |||
Report Folder | Return a list of report folders | no inputs | return folder name and id | ||
Report List | Return a list of reports | optional filter for folder id, report type, last view, last run | return report name, report format, | ||
Record List from Report | Return a sobject collection of all the records on a specified report | input report id | sobject collection of records and fields on the report | Goal is to allow end-user to select a report of records that they defined using a report and perform a screen flow against those records. For example, mass create child records, mass update, mass delete etc | |
Record List from ListView | Return a sobject collection of all the records on a specified list view | input listview id | sobject collection of records and fields on the list view | Goal is to allow end-user to select a report of records that they defined using a list view and perform a screen flow against those records. For example, mass create child records, mass update, mass delete etc | |
Compare Collections and return unique and common values | Functionality to be the same as here, but for record collections. | Two collections | Three collections (common, unique to coll1, unique to coll2) | Peter Kaszas | I am using the datable from unofficialsf.com and would like to be able to get the difference between the total list and the selected list. |
Slice A big collection (Take first N Records) | It takes an input sobject collection and spits out 2 collections based on the first N records of a number you provide, and puts the rest in another collection | One sObject Collection | Two sObject Collections | Adam White | Many times it is useful to chunk out operations to abide by Salesforce limits – it’s especially useful in Screen flows when its easy to maintain limits by keeping tabs on your DML and then letting the user hit ‘Next’ if Flow detects you’re approaching a limit. This would be a handy action to have for that |
Output formula value for each record in Collection | 1. Return value from a formula input using available columns in an sObject Collection Variable 2. Add values to a Collection Variable 3. Optional: output unique values | One sObject Collection Variable | One Collection Variable | Rick Haag | Formulas fields are often created for the purpose supporting automation and are not shared via the UI to users. This option can reduce the overhead of multiple formula fields in place soley for the purpose of automation. |
Support Apex Defined Objects | Update the processors to support Apex Defined Objects in addition to SObjects | One Apex Defined Collection Variable | One Apex Defined Collection Variable | Eric Smith | |
Map more than strings | Add at least number and date to the mapping. | I suppose the tricky bet is how to describe the value of the mapping pair. I suggest leaving it as text and converting to number and converting to date inside the map code. | Terry Cole | Mapping of text area works. Mapping of picklist value works (from string). Mapping of long text area seems to generate fault. Mapping of number (from string) and date (from string) runs but does not make changes. | |
Count Records and Fields | Documentation says field and value are optional, but screen configuration shows them as required | Just wants a quick count. Can so with collection count feature of assign, however. Just wanted cleaner solution. | |||
Minimum date | Insert a list of dates, and returns the minimum. Quite cumbersom via formulas, seems easier in apex | Collection of dates | |||
Strip Nulls | Remove null records from a record collection | Collection of sObject records | New collection of sObjects with null records removed | Charles Thompson | Anything you can do to avoid a loop is great! As it is, to remove null records, it appears you have to compare each record against a single record variable (of the same sObject) that has not been initialised. |
Get Child Collections | Pass in a *collection of records* and get a single collection of *the children of all of the input records* of a particular object type | 1) Collection of object records (or list of IDs) 2) Name of child object | Collection of records of the object type specified | Rachel Beach | Basically “Get Child Collection” but you can pass in a list of records rather than having to create a loop and call the action for each parent record |
Get Records where Field in Collection | Get all records where a field is equal to one of the values in a collection (select * from [object] where [field] IN [input collection]) | 1) Name of object 2) Name of lookup field 3) Collection of record IDs | Collection of records of the object type specified | Rachel Beach | Not sure if this needs to be different for lookup fields vs other types of fields but I personally want it for a lookup field |
Installation
Install Prerequisites
Before installing this component, you need to have in your org the Screen Component and Action Base Packs.
Install those here
3.1.1 5/14/23 Production Sandbox
- Added Return First N Records action
- Changed api version on DeepClone down to 42to keep it working
Old Versions
3.0.4 10/10/22 Production Sandbox – improvements to FindCommonAndUncommon and MapCollection
3.0.3 Unmanaged 4/21/22 (Production or Dev)
3.0.3 Unmanaged 4/18/22 (Sandbox)
3.0.1 Unmanaged 4/18/22 (Production or Dev)
3.0.1 Unmanaged 4/18/22 (Sandbox)
3.0.0 Unmanaged 4/17/22 (Production or Dev)
3.0.0 Unmanaged 4/17/22 (Sandbox)
1.34 Unmanaged 2/25/22 (Production or Dev) – bug fix for upsert
1.34 Unmanaged 2/25/22 (Sandbox)
1.33 Unmanaged (GetRecordsFromIDs now additionally outputs records as a JSON string)
1.32 Unmanaged (enhances Upsert to support JSON record data)
1.31 Unmanaged (adds support to Map Collection for mapping numeric fields )
1.30 Unmanaged (bug fix)
1.29 Unmanaged (adds permission set 6-19-21)
1.28 Unmanaged (adds CollectionCalculate 5-23-21)
1.27 Unlocked (add Dedupe Records)
1.25 Unlocked (add Get Records from Ids 3-8)
1.23 Unlocked (add Find Uncommon and Common 2-13)
1.20.2 Unlocked (some bug fixes)
1.20.1 Unlocked (adds bulkification to remaining unbulkified actions)
1.19.3 Unmanaged (fix bug in Generate Collection Report)