Create rollups on lookup records with a flow and a free app

Create rollups on lookup records with a flow and a free app

Wouldn’t it be nice if Salesforce gave us the ability to create roll ups on records related by lookup?

Why do master detail relationships get to have all the rollup fun!?

Assets are not available as a rollup from the account record. Why not?! So annoying.

Luckily…..

James Simone created the “Apex Rollup” app that is perfectly suited for this need.

Back the old days, I’d install DLRS, but over time I found there were serious limitations as well as technical debt that didn’t play nicely with many of the other apps I was installing.

That led me to CMDT, which was a lot less straightforward in its setup and config (in my opinion) but had more capabilities and fewer issues.

Now that everyone is on the flow train, and flows can kinda sorta do the rollup functionality, James Simone built an action for flows that works beautifully with the CMDT functionality

I found this app while reading the article titled “Create powerful rollups in your flows with a single ‘Perform Rollup’ action.

Here’s my YouTube video walking you through the installation and config process.

Without further ado, here’s how to install and configure James’ free “Fast easy rollups in Salesforce Flow” app.

Login to a production or sandbox Salesforce environment.

Scroll down on the Rollup App page (linked here) and select the package you need.

Verify the installation is complete from Installed Packages.

Configure the rollup settings custom setting (one time step).

  • Go to Setup – Custom Settings
  • Click “Manage” by Rollup Settings
  • Click the Edit button above the “Default Organization Level Value” heading
  • Check the “Is Enabled” box
  • Save

Assign yourself the app’s Permission Set.

Click Manage Assignments on the “See Rollup App” Permission Set
  • Setup – Permission Sets
  • Click Manage Assignments on the “See Rollup App” Permission Set
  • Assign the permission set to yourself and any other applicable users

Create the custom field that will store the rolled up information on the parent object.

  • Our use case is counting the number of Assets related to the Account, so we need a number field on the Account to hold the count number.

Create the Custom Metadata Type.

a. Click the Manage Records button beside the metadata type called “Rollup”

b. Click the “New” button

c. After naming the record, set the Parent Object as Account and rollup assignments as outlined in the screenshot above

d. Assign the child record logic of counting the number of Assets related to the parent Account record.

e. Set the Rollup Operation as Count. Set the Rollup Control as “Org Defaults.”

f. Save the record

Create a record-triggered flow to run the rollup when child records are created or edited

a. Create a new Record-Triggered Flow

b. Configure the flow’s start criteria

  • Object = Asset
  • Trigger the flow when = A record is created or edited
  • Condition Requirements = None
  • Optimize the flow for = Actions and Related Records

c. Add an element.

d. Select “Assignment” under Logic

e. Create a new resource from the variables field

f. The resource type is “Variable”

g. Set the variable parameters as follows:

  • Data Type = Record
  • Object = Asset
  • Allow multiple values when checked = Checked
  • Available for input = Checked
  • Click the Done button
  • Operator = Add
  • Value = Click the little icon to the left of $Record for Asset
  • Click + Add Assignment to create the Prior record collection variable

h. Create a second resource like how you created the CurrentRecord variable; name it PriorRecord.

  • When completing the assignment, click the globe icon beside Record__Prior and set the Operator as Add
  • Click Done

The assignment will look like the above screenshot.

i. After you click done, click the + sign to add another element.

  • Select Action under Interaction.
  • Choose “Rollups” from the left side panel
  • lick in the Action dropdown and choose the value named “Perform Rollup__mdt-based rollup”
  • Name the action
  • Set the “Object for prior records to rollup and records to rollup” as Assets
  • Type UPSERT into the Rollup Context field
  • Toggle “Defer processing?” to “Include” and select the global constant false value
  • Scroll down and toggle the following two fields to “Include” and set as follows:
    • Set “Prior Records to rollup” with the record collection variable you made to collect prior records
    • Set “Records to rollup” with the record collection variable you made to collect current records

j. Save and activate the flow.

The flow should look like this when it’s finished.

Create a second flow to recalculate the rollup when child records are deleted.

  • Object = Asset
  • Trigger the flow when = A record is deleted
  • Condition Requirements = None
  • Click Done
  • There will be no Prior Record variable on this flow, so create one variable for collecting current records. Follow the steps from the first flow above.
  • Click the Done button
  • Create a new action just like in the first flow, except this time you will type DELETE into “Rollup Context”
  • Defer processing will be false
  • “Records to rollup” = the variable you built in the previous step
  • “Prior records to rollup” is not applicable here, so you’ll keep it toggled to “Don’t include”
  • Click “Done
  • Save and activate

Test your flows by creating and deleting child records to verify that the rollup is calculating as expected.

To backfill the existing records with an accurate value in your new rollup field, you can run a process using the installed app.

FYI You should only need to do this when you create a new rollup and corresponding field that needs to be backfilled, as your flows will handle any other recalculations when changes are made to the child record (create, edit, delete.)

  • Type ‘rollup’ in the app launcher search box and click on the Rollup app in the results
  • The single tab in this app is called Recalculate Rollup
  • Toggle “Run off of CMDT?” to Active
  • Click the “Select Calc Item” field and select the child type you’re looking to run
  • Once a child type is selected (like in my case, Assets), you can:
    • Recalculate rollup values one field at a time (like in my example, there’s just one rollup in place for Assets
    • Or, if you have multiple rollups per child object configured, you can run them all at once by checking all of the boxes
  • The screen will lock while the process runs and will let you know when it is complete

Good job! Your new field is populated and set to update automatically.

Leave a Reply

%d bloggers like this: