Roll-up summary fields are great! But it’s important to remember that they are only available between objects with a Master-Detail relationship.
Never fear, as in this article we’ll be learning how to create roll-up fields between objects that have a Lookup relationship using the mighty Flow Builder. This includes a simple use case as well as a quick walkthrough of Flow-friendly roll-up features to help you get started.
What is a Roll-Up Summary Field?
A roll-up summary field is one that aggregates data from a child object to a parent object that shares a Master-Detail relationship. Roll-up summary fields can use the COUNT, SUM, MIN, and MAX functions. For example, we could use a roll-up summary field to display the total value (amount) from Opportunities on a related Account.
Even better, roll-up summary fields can have filter criteria, so we could choose to display the total Opportunity value from won opportunities on a related Account.
Unfortunately, roll-up summary fields are only available for objects in a Master-Detail relationship, and are not available for those that have a Lookup relationship.
Create Roll-Up Summary Fields with Flow
Historically, Admins have turned to outside tools to achieve roll-up summary fields between objects that have a Lookup relationship. These tools include Declarative Lookup Rollup Summaries, better known as DLRS (which I absolutely adore!), and Rollup Helper.
However, it is also possible to achieve this functionality using Flow. Flow can implement many types of roll-up logic: Count, Summary, Min, Max, Average, First, and Last. Logic can range from simple to complicated. Here are a few common examples of aggregation:
- How many Contacts does an Account have?
- How many Contacts of a specific role does the Opportunity contain?
- How many team members does an Account have?
When to Trigger the Flow?
A roll-up field on the parent record needs to be re-calculated in these three cases:
- Child record creation
- Child record update
- Child record deletion
Use Case Walkthrough – Open Cases on an Account
When our Sales reps go to a meeting with an existing customer, ready to make a big pitch, wouldn’t it be useful to give them the ‘heads up’ in case there’s anything wrong? It would be great to let them know how many open Cases there are related to the Account.
We want to know the Count of open Cases related to an Account.
Create a custom number field on the Account called ‘Number of Open Cases’.
Create a record-triggered flow called ‘Calculate Number of Open Cases On Create/Edit’.
Choose to trigger when ‘A record is created or updated’. Select ‘Case’ as your object.
Create a new Flow resource:
- Variable > Type = Number > ‘Open Cases Count’
Add a Flow ‘Get Records’ element called ‘Get Open Cases’.
Assign the size of the list of related open Cases to your Count Variable. This step helps you understand how many open Cases were imported. Don’t forget to change the Operator to ‘Equals Count’.
Create an ‘Update Records’ element to update the Account.
Save and activate your Flow.
We’ll repeat the process and create a new Record-Triggered Flow that will launch if a record is deleted called ‘Calculate Number of Open Cases On Delete’. You can save time by clicking ‘Save As’ on your current Flow and choosing to save as ‘A New Flow’.
If you’ve done a save as, you now need to change the ‘Start’ to run when a record is deleted.
Repeat steps 4, 5 and 6 above. If you cloned your previous Flow, then move straight on to step 11.
This is where things get a little different. The record count we have just created still includes the record we are in the process of deleting, therefore we need the count of open Cases minus 1. We’ll create a new variable. This will be a formula.
Either create a new Update Records action or, if you cloned your previous Flow, edit the ‘Update Account’ action to ensure the field value is now using our ‘Cases_Count_Minus_One’ value.
Save and activate your Flow.
That’s it! We’re done.
You can now add your field to the page layout, compact layout and so on. I had some fun with Flow and used a Screen Flow to display a message on the Account screen!
Now that you are familiar with the mechanics and main services of Roll-Up Summary field creation (with the powers of Flow Builder!), you can apply these principles to more creative and complex use cases, e.g. Count Distinct, Concatenate, and many others. Good luck!