-
-
Notifications
You must be signed in to change notification settings - Fork 30
Perform Rollup On Records Base Invocable Action
This Invocable Action is referred to as the "base" action because it comes from Rollup.cls
, the entry point for all things apex-rollup
. It works best when called from a Record-Triggered Flow, where you have access to the $Record
and $Record_Prior
variables.
Let's start from the beginning by going screen-by-screen on a new Record-Triggered Flow:
To properly pass your input variables to the flow, create two Collection variables (you can call them whatever you'd like; I tend to go with Records
and OldRecords
):
- the easiest way to do this is to start in an Assignment element and click the box under the "Variable" section
- click "New Resource"
- Resource Type: Variable
- API Name: again, I usually go with "Records" and "OldRecords"
- Description: optional
- Data Type: Record (be sure to check off the "Allow multiple values" checkbox)
- Object: select the same object that your Record-Triggered flow starts from
- Availability Outside The Flow: make sure to check off "Available for Input"
- select your newly created resource and change the Operator value to "Add"
- use
$Record
as the value for your "Records" collection, and$Record_Prior
for the "OldRecords" collection. Note that the assingment of$Record_Prior
is only necessary if you're using a Record-Triggered Flow set to run whenA record is created or updated
Here's what your Assignment element should look like once all that jazz is done:
Once you've assigned your variable(s) to their respective collections, you're ready to interact with the base invocable action! Click the "+" sign on your flow path and under "Interactions", select "Action" - by default, the actions are brought up with "Categories" as the filtered-on drop-down on the left side of the pop-up. If you scroll down within this categorized list, you'll find "Rollups" as one of the listed categories:
Now, when you start typing in the Action search bar on the right side of the pop-up, you'll only see options out of the three invocable actions included with apex-rollup
:
The first search result, Perform rollup on records
is the "base" invocable action. Once you've selected that, the pop-up will transform and you'll be able to start entering the required information for this Action to work! You'll have to fill out both objects under the "Select Objects" header with the type of child object you're working with* (footnote below) before the other invocable fields will be shown:
*: Unless the rollup is triggered from the parent using the Is Rollup Started From Parent
optional field, in which case you would be selecting the parent type here.
Once you've filled out these fields, the rest of the Action's fields are displayed:
Now, let's walk field-by-field through the pictured options on the base Action so that you know exactly how to fill it out:
-
Calc Item Calc Field
- the field on your child object that contains the value(s) that will be rolled up. Note that you are using the API name (including the__c
for custom fields) for the field here, not its field label. -
Calc Item Lookup Field
- the field on your child object that contains the reference to the parent object. While "lookup" field is part of the name here, the field does not have to be a lookup; any text field containing a Salesforce Id or other unique identifier on another object will work. LikeCalc Item Calc Field
, use the field's API name. -
Rollup Object API Name
- this is the API name for the parent object. Going off of the example pictured above, I would useRollupParent__c
here. -
Rollup Object Calc Field
- the API name of the field where the rolled-up values will be stored. -
Rollup Object Lookup Field
- the API name of the field that lines up with the parent's unique relationship to its children (this field should match, per parent, the child values foudn inCalc Item Lookup Field
). UsingId
here will be very common when the relationship is a straightforward lookup relationship. -
Rollup Operation
- the values here correspond to the values found on theRollup__mdt.RollupOperation__c
picklist (and they should be written out in all caps):- AVERAGE
- CONCAT_DISTINCT
- CONCAT
- COUNT_DISTINCT
- COUNT
- FIRST
- LAST
- MAX
- MIN
-
Rollup Operation Context
- for a Record-Triggered Flow, this describes when the flow will run:- INSERT - if your flow only runs after a record is created
- UPDATE - if your flow only runs after a record is updated
- UPSERT - if your flow runs after a record is created or updated
- REFRESH - if you want the rollup action to fully recalculate the rollup values for any parent object that has children records passed through the flow
- DELETE - if your flow runs before a record is deleted
Work in progress - check back here for more!