Collection Actions 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.

Install Current Version

Installation links at the bottom of this page.

Video Demo

Updates

New! 7/20: Upsert
New! 6/20: Report Generation

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;

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

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’)

Inputs

  • 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

Outputs

  • 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:

  1. use its ID and retrieve the record
  2. retrieve the values of any fields present in the formula string
  3. use the formula evaluator to evaluate the formula
  4. 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

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 shownFieldsa 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
tableStyleStringwill be inserted into the table html as a style attribute: <table style=”[tableStyleString]”>
headerStyleStringwill be inserted into the <th> tags as a style attribute
rowStyleStringwill be inserted into individual row tags (<tr>) as a style attribute
showHeaderBoolean
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 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 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;

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;

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;

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

For more info, see https://unofficialsf.com/create-or-update-with-the-new-upsertrecords-action/

Discuss Additions, Changes, Improvements, Requests

Thinking of a great addition to this package? Propose it at https://quip.com/6jg3AyrUEFnw/Collaboration-Sheet-for-Flow-Collection-Processors

Installation

Install Prerequisites

Before installing this component you need to have on your org the Flow Base Components support package

Install that here.

1.20.2 Unlocked (some bug fixes)

Old Versions

1.20.1 Unlocked (adds bulkification to remaining unbulkified actions)

1.19.3 Unmanaged (fix bug in Generate Collection Report)

View Source

Source