Loading

Create Roll-Up Summary Fields Utilizing Salesforce Flow

Дата публикации: Jul 6, 2026
Описание

A roll-up summary field in Salesforce aggregates data from a child object to a parent object within a Master-Detail relationship. These fields use aggregation functions including COUNT, SUM, MIN, and MAX to calculate values across related child records.
For example, a roll-up summary field on the Account object can display the total opportunity amount for all related Opportunities. You can also apply filter criteria — for example, showing only the total value of won Opportunities associated with an Account.
Important: Roll-up summary fields are only available for objects in a Master-Detail relationship. They are not available for Lookup relationship fields.
For objects with a Lookup relationship — or for more complex aggregation logic — you can use a Salesforce Flow (Record-Triggered Flow) to achieve similar results. This article demonstrates how to build a Flow that counts the number of Cases related to each Account and writes that count to a number field on the Account object.

Решение

Use Case: Count Related Cases on the Account Object Using a Record-Triggered Flow

This example shows how to build a Salesforce Record-Triggered Flow that calculates the count of Cases related to an Account and stores that count in a custom number field on the Account object.

Step 1: Create a Custom Number Field on Account

  1. In Salesforce Setup, go to Object Manager and open the Account object.
  2. Click Fields & Relationships, then click New.
  3. Select Number as the field type and click Next.
  4. Configure the field with 0 decimal places (since this will store a whole-number count).
  5. Complete the field creation and save it. Note the field's API name for use in the Flow.

Step 2: Open Flow Builder and Create a New Record-Triggered Flow

  1. In Salesforce Setup, type Flows in the Quick Find box and click Flows.
  2. Click New Flow.
  3. Select Start From Scratch, then click Next.
  4. Select Record-Triggered Flow, then click Create.
  5. For the trigger object, select Account.
  6. Set the entry condition to trigger when A record is created or updated.
  7. Leave the Entry Conditions as-is (no additional filter criteria).
  8. For Optimize the Flow For, select Actions and Related Records.

Step 3: Add a Get Records Element to Retrieve Related Cases

  1. On the Flow canvas, click the + icon after the Start element to add a new element.
  2. Select Get Records.
  3. Enter a Label (for example, "Get Related Cases") and an API Name.
  4. For Object, select Case.
  5. Add a filter condition: AccountId equals {!$Record.Id} (this filters for Cases related to the Account currently being processed by the Flow).
  6. Under How Many Records to Store, select All Records to store all matching Case records in a collection variable. Flow Builder automatically creates a collection variable for you.

Step 4: Add a Loop Element to Iterate Through the Cases

  1. Add a new Loop element after the Get Records element.
  2. For Collection Variable, select the collection variable created in the Get Records step.
  3. Configure the loop to iterate For Each Item in the Collection.

Step 5: Create a Number Variable to Count Cases

  1. In the Flow's resource panel (or via the Manager tab), click New Resource.
  2. Select Variable as the Resource Type.
  3. Set the Data Type to Number and configure it with 0 decimal places.
  4. Give it an API name such as CaseCount and set the default value to 0.

Step 6: Add an Assignment Element Inside the Loop

  1. Inside the Loop (on the loop body path), add an Assignment element.
  2. Set the Variable to your CaseCount number variable.
  3. Set the Operator to Add.
  4. Set the Value to 1.

This causes the Flow to increment the CaseCount variable by 1 for each Case record in the collection.

Step 7: Add an Update Records Element After the Loop

  1. After the Loop ends (on the path outside the loop), add an Update Records element.
  2. Select Use the account record that triggered the flow (or reference {!$Record}).
  3. Map your custom number field on the Account object to the CaseCount variable value.

Step 8: Save and Activate the Flow

  1. Click Save and provide a name for the Flow.
  2. Click Activate to enable the Flow so it runs automatically when Account records are created or updated.

When the Flow runs, it retrieves all Cases related to the triggering Account, counts them, and updates the custom count field on the Account. This achieves a roll-up summary count effect for a Lookup relationship.

Дополнительные ресурсы

Build a Flow

Meet Flow Builder

Номер статьи базы знаний

002722670

 
Загрузка
Salesforce Help | Article