Collection Processors for Flow (Sort, Filter, Find, Join, Map, and more)

PREVIEW Requires Spring ’20 Org

Install Unmanaged 1.12 (taft)

This package of Flow Actions really needs a video and a demo flow to do it justice, but I wanted to get these out there for early adopters who want to play with the power that Flow’s new support for generic SObject provides.

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 Unmanaged Package (coming soon. for now, you can copy and paste from the source and the actions will work on Spring ’20)

View Source

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

Version List

Install Unmanaged 1.12 (taft)

1.1 Adds Count Records And Fields & Extract Strings From Collection

1.0 Install Unmanaged Package

View Source

View Source

18 replies
  1. Chris V
    Chris V says:

    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 shifts in queue membership at times for OmniChannel.

    Reply
    • Alex Edelstein
      Alex Edelstein says:

      My guess is that these general purpose actions are probably not the best way to solve your problem. For your situation, it sounds like an action Get Group Membership that takes a user and returns a list of Group id’s would be useful. And an action Get Queue Users. Those wouldn’t be hard for someone to build. I’ll put it on my backlog, but hopefully we can get some other motivated apexers to crank some of these out and add them to the directory.

      Reply
  2. Tamar Erlich
    Tamar Erlich says:

    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?

    Reply
  3. Adam White
    Adam White says:

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

    Reply
  4. Rick Haag
    Rick Haag says:

    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 won’t work with a non-generic sObject.

    Lastly, is there a plan on the roadmap to develop a SOQL statement option in the “Get Records” Element of Flow?

    Excellent addition! Thank you. Thank you.

    Reply
    • Chris V
      Chris V says:

      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.

      Reply
  5. JessieRymphj
    JessieRymphj says:

    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!

    Reply

Trackbacks & Pingbacks

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

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply