How to Create Roll-Up Summary Field using Salesforce Flow

In Salesforce, a roll-up summary field calculates values from related records, such as those in a related list. This field displays values in a master record based on the values of fields in a detailed record. With the help of flow, we can automate the process of creating a Roll-Up Summary field.

In this Salesforce tutorial, we will learn to Create Roll-Up Summary Field using Salesforce Flow.

Prerequisites

To create a Roll-up summary field using flow in Salesforce, you must have a custom Number field in the object in which you want to create the roll-up summary field flow.

Create Roll-Up Summary Field Using Salesforce Flow

In this example, we will create a Roll-up summary field in the Account object, which will display the current number of contacts associated with that Account record.

To Create a Roll-Up Summary Field With a Salesforce Flow, we will create an Auto-Launched flow that will be a sub-flow of a record-triggered flow.

We will call this auto launch flow with record trigger flows for different criteria like trigger flow when contact is created and another when the record is deleted or updated.

Now navigate to the setup page of Salesforce, and follow the below steps.

1. On the setup page, go to the Quick Find box and search, then select Flows under the heading Process Automation.

Create a Roll-up summary field using flow in Salesforce

2. In the Flows setup window, click on the button New Flow.

3. Select the option Auto-Launched Flow and click on the Next button.

Use Flow to create roll up summary field in Salesforce

4. In this flow, we will create a variable to store the parent record ID. To do so, click on the toggle icon at the left and click on the button New Resource.

Create Roll-Up Summary Fields Using Salesforce Flow

5. Enter the below details to create the variable for storing the Account ID.

  • Select the Resource Type as a Variable.
  • Enter API Name as accountId.
  • Select Data Type as Text.
  • Make the variable available for input and click Done.
Implementing Roll-Up Summary Fields Using Flows

6. In the same way, create another Resource with the below details that will count the records for the roll-up summary field.

  • Select the Resource type as Variable.
  • Enter the API Name as Count.
  • Select the Data type as Number and better to keep Decimals as 0.
  • Make this variable available for input and click the Done button.
Implementing Roll-Up Summary Fields Using Flows in Salesforce

7. Add a Get Record element to the flow.

See also  How to Delete Records using Flow in Salesforce

8. Enter the below details to define the conditions to get the flow.

  • Enter the Label and API Name for the get record element.
  • Select the Object as Contact.
  • In the Condition Requirements, select the Field as AccountID, Operator as Equals, and Value as variable accountId.
  • Activate the radio buttons, Select All Records, and Choose fields, and let Salesforce do the rest.
How to create a Roll-up summary field using flow in Salesforce

9. Add a Loop element to the flow, then enter the Label and API Name for the loop element. In the field Collection variable, select Get Contacts ( the get element created above).

Create a Custom Roll-up summary field using flow in Salesforce

10. In the loop, add an Assignment element, then enter the Label and API Name of the assignment.

In the section, Set Variable Values, select the Variable as Count (the second created to store roll-up summary field ), Operator as Add, and Value as 1.

Use auto-launched flow to create a Roll-up Summary field in Salesforce

11. Add an Update Records element and enter the Label and API Name for the update record element.

Activate the radio button, Specify conditions to identify records, and select the Object Account.

Create a Roll-up summary field in Salesforce using flow

12. To define the conditions to get the ID of the account record page, set Field as Id, Operator as Equals, and Value as accountId (text variable).

In the section Set Field Values for Account Records, select the number field as the Field for which you want to create the roll-up summary and then select the Value as Count ( variable of roll-up summary field).

Create a Roll-up summary field in Salesforce using Flow builder

13. Click on the Save button.

Use Salesforce flow to create Roll-up summary field

14. Enter the Label for the flow, and the Flow API Name will be auto-filled according to the entered label.

At last, click on the Save button.

Use Flow builder to create roll up summary field in Salesforce

15. Activate the flow, and for that, click on the Activate button at the top.

Salesforce Custom Roll-up summary field using flow builder

This Auto-Launched flow will function as a roll-up summary field to the selected number field, and further, we will create the trigger flow with different conditions that will call this auto-launched flow according to the conditions configured in them

Create a Record-triggered flow to call the Auto-Launched flow

We have defined the above auto-launched flow as a roll-up summary field, and after that, we need to call the flow according to the changes in the record. Here, we need to create different triggers when the records are created, updated, and deleted.

Trigger the flow when the Record is Created

In the below steps, we will create a Record triggered flow that will update the roll summary field when a record is created in the parent object.

See also  Conditional Visibility in Salesforce Flows

To create a Record triggered flow navigate to the Flows setup and follow the below steps.

1. In the Flows setup window, click on the button New Flow.

2. Select the option Record-Triggered flow and click Create.

How to use Flow to create roll up summary field in Salesforce

3. Enter the below details to configure the flow to trigger.

  • Select the Object as Contact.
  • In the Configure Trigger section, activate the radio button ‘A record is Created’.
  • In the Condition Requirements, select the Field as AccountId, Operator as IsNull, and Value as False.
Create Roll-Up Summary Fields Using Salesforce trigger Flow

4. Add a sub-flow element to the flow.

Use Flow to create a Salesforce roll-up summary field

5. Enter the below details to define the sub-flow element.

  • In the Refreced Flow, select the Auto-launched flow that we created in the above steps.
  • Enter the Label and API Name for the Sub-flow element.
  • Activate the Set input Values AccountId and Count.
  • Enter AccountId as Record>AccountId and Count as 0.
Create a Sub flow for a roll-up summary field in Salesforce

6. Now save this flow by entering the Flow Label and Flow API Name.

Roll-up summary field flow in Salesforce

7. At last, activate the flow.

Create Roll-up summary field using flow in Salesforce

We have created a trigger flow that will update the roll-up summary field when a contact is added or created in an account record.

Trigger the flow when a record is updated

Now, we will create a trigger flow to call the auto-launch flow when a record is updated, i.e., when an Account contact is transferred to another account.

1. Open the Trigger flow that we have created for the updated records in the above steps, click on the Edit button, and change the trigger configurations as follows.

  • Activate the radio button “A record is Updated” under the heading Configure Trigger.
  • In the trigger condition requirements, select Field as AccountId, Operator as Is Changed, and Value as True.
Create a Custom Roll-up summary field using flow builder in Salesforce

2. Add a Subflow element to the flow.

3. Enter the details to define the new subflow element.

  • In the Referenced flow field, select the auto-launched flow that we have created above.
  • Enter the Label and API Name of the sub-flow element.
  • In the section Set Input Values, activate the variable fields AccountId and Count.
  • Select the AccountId as Record Prior > Account id and Count value as 0.
Use Salesforce Flow builder to Create a Roll-up Summary field

5. Click on the Save button in the flow builder, then in the next window, click on the button New Flow, enter the new Label and the API Name for this trigger flow, and click Save.

Create a Roll-up summary field for Account records using flow in Salesforce

6. At last Activate this flow.

Use Salesforce flow builder to create Roll-up summary field

Now, we have created a trigger flow that will update the roll-up summary field when a contact in the account is transferred from one account to another.

See also  How to Update Related Records using Salesforce Flow

Trigger the flow when a record is deleted

To create a trigger flow to call the auto-launch flow when a record is Deleted, go to flow setup > Click New Flow > Select Record Trigger Flow and click Create.

1. In the trigger flow, define the following fields.

  • Select the Object as Contact.
  • In the section Configure Trigger, select the option ‘A record is deleted.’
  • In the Condition Requirements, select the Field as AccountId, Operator as Is Null, and Value as False.
Salesforce Roll-up summary field using flow

2. Add a Sub-flow and configure it in the following way.

  • Enter the Label and the API Name of the subflow.
  • In the field Reference Flow, select the Auto launched flow that we have created above.
  • In the section Set Input Values, activate the variable fields AccountId and Count.
  • Select the AccountId as Record > Account id and Count value as -1.
Create a Roll-up summary field for Salesforce object using flow

3. Save the flow by entering the Flow Label and the Flow API Name then click Save.

Create a Roll-up summary field for related record in Salesforce using flow

4. At last, activate the flow.

Create a Roll-up summary field for related record in Salesforce using flow builder

Now we have created the trigger flows for the conditions when the contact record will be created, update and deleted in a Account object record. These trigger flow will call the auto-launched flow that will update the number of contacts according to the current changes.

After this navigate to the Account record and go to the Number field that you have used in the above auto launched flow, there will see the number of contacts present in the current Account record.

In this way, we can create a Roll-up Summary field with a Salesforce Flow by following the above steps.

Conclusion

In Salesforce, Flows can be used efficiently to create custom roll-up summary fields that can be configured according to the requirements of your organization. By using Flow, we can automate complex business processes and ensure data accuracy within the Salesforce environment.

By following the above steps, you might have understood the process of creating a roll-up summary field with a Salesforce flow.

You may like to read: