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.

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

Extract Strings From Collection

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.

Inputs

List<SObject> inputCollection;

String fieldName;

Output

List<String> stringList

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

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.

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. Not particularly pretty, but useful for debugging and a good building block to show what can be done by doing string manipulations on collections.

Inputs

List<SObject> inputCollection;

String shownFields

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.

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:

{“sortkeys”: [
{“field”:”Name”,
“direction”:”asc”} ]}

Inputs

List<SObject> inputCollection;

String sortKeys;

Outputs

List<SObject> outputCollection;

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

1.14 Unmanaged

Old Versions

1.13 Unmanaged

1.12 unmanaged (taft)

1.1 Adds Count Records And Fields & Extract Strings From Collection

1.0 Unmanaged Package

View Source

Source

40
Leave a Reply

avatar
15 Comment threads
25 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
12 Comment authors
JuulAlex EdelsteinAdam WhiteJessieRymphJosh Dayment Recent comment authors
  Subscribe  
Notify of
trackback

[…] unmanaged package of collection actions is available for installation here on Spring ’20 […]

Chris V
Guest
Chris V

Thank you for posting these. I’ll be eager to test them out once sandbox preview begins! Do you think any of these will help with the following use case? Its the one I’ve had the most trouble solving with flow. Right now, it takes a lot of loops to get close – Output: An sObject collection of users that are member of a queue – Output: An sObject collection of Groups (queues) that a user is a member of Essentially I built a screen flow to mass add and remove queue members. We have a contact center that requires mass… Read more »

Tamar Erlich
Guest
Tamar Erlich

Hi Alex, I have installed the package in a Spring ’20 org but the actions are not showing up in the list of available actions in the flow builder. The installed package icon looks different than a regular managed package icon, I’m assuming it’s due to the new SFDX packaging? Is there something that should be done to enable this package after installation?

Adam White
Guest
Adam White

In the Filter collection action – how are MSP’s handled? What Operator is being used to do the filtering? Looking at the code I assume it’s just ‘Equals’?

Adam White
Guest
Adam White

Sorry I meant the ‘Find’ action.

Adam White
Guest
Adam White

Separately looks like the formula expression screen component is missing from the ListActions repo – I only see the sortCollection LWC.

trackback

[…] first upgrade to the Collection Processor package is […]

Rick Haag
Guest
Rick Haag

Alex, This is amazing! I briefly spoke with Shannon Hale at Dreamforce ’19 about the scenario of manipulating sObject Collection Variables. The specific use case was related reducing the need to run additional queries when all the data required for a flow can be available with a single query (Get Records Element). Options previous to these awesome additions where to loop or query again and again or sometimes both. With the support for generic sObjects, will this allow for the development of an action that will accept an actual SOQL statement? The ability to use options like Group by Rollup/Cube… Read more »

Chris V
Guest
Chris V

Actual SOQL is supported. I created a quick APEX action that accepts the SOQL query as a text and it returns an sobject collection. The only issue is dates are causing an issue since they are being converted into the wrong text format instead of datetime so I’ll eventually need to fix that.

JessieRymphj
Guest

I’m having the same issue as Tamar. I’ve installed/uninstalled/installed from the package link at the top, which installs version “ver 0.1” and doesn’t show the actions in flow. Thanks!

trackback

[…] to Alex Edelstein and UnofficalSF.com for an unmanaged package that performs this magic for us! Watch my video of how I use the “Map Collection” apex […]

Eric Smith
Editor

Alex, I’m trying to use Extract Strings from a Collection and the inputCollection input attribute is not letting me specify a collection.

Eric Smith
Editor

I may be using the wrong source. One of the Source Links on this page goes to Collection Processors and the other one goes to ListActions. I’m not sure what version the v1.12 package installs.

Alex Edelstein
Guest
Alex Edelstein

Did this resolve, Eric?

Eric Smith
Guest

No The Source Link at the top of the page is different that the Source Link at the bottom of the page. Whick one is accurate?

Alex Edelstein
Admin

Cleaned that up.

Johan Samuelsson
Guest
Johan Samuelsson

Hi Alex, I’m trying to use the Sort function, but how do you enter the SortKey. I just want to sort on ID to start with – will use it to remove duplicates in an sObject collection. BTW, really cool feature.

Alex Edelstein
Guest
Alex Edelstein

Did you see the doc example above?

Adam White
Member

Johan – stay tuned for an invoked action that can de-dupe a collection based off a field API name! Should be coming in the next couple weeks.

trackback

[…] the end of 2020, it will be possible to add Custom Property Editors to Collection Processor Actions. That will allow the SOQL Builder UI to not just exist in running Flows but also in the Execute […]

Josh Dayment
Guest
Josh Dayment

I am trying to use the Map Collection action and am receiving this error in my update step. My input collection has the id’s in my output it is showing my only my string keyvalue pairs.

Error Occurred: If you use a record variable to update or delete records, the ID value in the variable must be populated.

Alex Edelstein
Admin

This was fixed in the code. Do you know if you installed the latest 1.12 version from https://unofficialsf.com/list-actions-for-flow/ That version should have the fix….

Anonymous
Guest
Anonymous

I have that version I my sandbox I’ll update my production version and report back thanks!

JessieRymph
Guest
JessieRymph

I’m getting the same error, Alex, and I just updated to version 1.12.

Josh Dayment
Guest
Josh Dayment

I got it to work in my Sandbox I haven’t been able to get it into my Production Org due to some code coverage issues so waiting on it to move out of Beta.

Alex Edelstein
Admin

Ok, just published 1.13 to this page. Give it a try.

Alex Edelstein
Admin

Ok, just published 1.13 to this page. Give it a try.

JessieRymph
Guest
JessieRymph

Yes! It works! New blog post coming for you soon. THANK YOU!

Adam White
Member

Alex – How does the ‘Remove Record from Collection’ action differ from the normal ‘Remove from Position’ collection assignment operator? Both seem to take an integer value as an input.

Alex Edelstein
Admin

Functionally they’re the same. Semantically, I’d much rather simply use a Remove Record action than create an Assignment and apply a Remove from Position operator to a Variable.

Juul
Guest
Juul

Alex, I’ve used your component to delete all cases in the SPAM Queue: https://prnt.sc/rmds72 When I debug it it’s deleting all my SPAM cases. But when I change the flow to run it once a week I’m getting an error that the “Profile does not have access to: removerecordincollection”. Apparently the flow is started by the Platform Integration User which has a chatter free license. When I change this to a Salesforce license with an admin profile I still have the same issue. How can I resolve this? –> FIXED by granting this apex class to the profile. BUT I’m… Read more »

trackback

[…] Install Collection Actions here. […]