Create Roll-up Summary Fields Using Salesforce Flow

Share this article...

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:

  1. Child record creation
  2. Child record update
  3. 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.

Step 1

Create a custom number field on the Account called ‘Number of Open Cases’.

Step 2

Create a record-triggered flow called ‘Calculate Number of Open Cases On Create/Edit’.

Step 3

Choose to trigger when ‘A record is created or updated’. Select ‘Case’ as your object.

Step 4

Create a new Flow resource:

  • Variable > Type = Number > ‘Open Cases Count’

Step 5

Add a Flow ‘Get Records’ element called ‘Get Open Cases’.

Step 6

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

Step 7

Create an ‘Update Records’ element to update the Account.

Step 8

Save and activate your Flow.

Step 9

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.

Step 10

Repeat steps 4, 5 and 6 above. If you cloned your previous Flow, then move straight on to step 11.

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.

Step 12

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.

Step 13

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!

Summary

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!

Read more:

3 thoughts on “Create Roll-up Summary Fields Using Salesforce Flow

  1. Hello Team,

    In above scenario when a case record is deleted then it is not updating the count on Account object field. What could be the reason behind it ? The sub flow is executed before the record is deleted ?

Add Comment