Roll Up Summary using Flows

Roll Up Summary using Flows
Implementing roll-up summary fields using flows

How often have we wondered if there was a way to work some of the magic of Master-Detail in lookups as well! In most cases, the feature of the roll-up summary without having to change lookup to master-detail would top the list of such wishes. Unfortunately, the feature is not available for lookups out-of-the-Box. But, here we are to the rescue.

In this blog, we’ll take you through a series of steps that would help in imitating the roll-up feature in case of lookups with the help of Lighting Flows.

Limitations:
The OOB Roll-up summary works when there is a master-detail relationship between the objects.
Use Case:

A custom object named Pricing under Opportunity has a lookup relationship. Amount fields need to be rolled up as a sum whenever pricing is created or updated under the opportunity. Clients want to have an alternative that sums up the amount. We can achieve this by creating two flows: one triggers when we create or update a record and the other when we delete a record.

Let us deep-dive into the step by step process –

Creating the flow when creating or updating the records:

  1. Log in to the org and go to flows. Click on Create New Flow.
  2. Choose Record Triggered Flow from the “All + Templates” tab.
  3. We need to select when we want this to get triggered:
    1. Choose “a record is created or edited” for Trigger the Flow.
    2. Choose “Action and its related records” to Optimize the Flow.
  4. We need to get all the child records associated with a parent record. For this purpose, we need to use the Get Records element.
    1. Give the Label and Name
    2. We need to filter the records based on the Id value present on the child record to the parent record.
    3. Get all the records.
  5. We need to loop over the records to perform the operations we need to do:
    1. Use the Loop element and add the “Get Records” API name in the collection variable.
    2. Specify the direction from First Item to Last Item.
  6. Now create a variable that stores the value from the child’s record – this operation must be done with the Assignment element.
    1. Create a variable by clicking a new resource and selecting resource type as variable
    2. Give the variable an API name and currency as data type.
    3. As we need to get the sum of all records for the specified field, choose the operator as ADD.
    4. Assign the value with the field name you need to get the sum from the current loop.
  7. Now, here comes the final part of updating the records. After all iterations, we must update the parent object with child field values.
    1. Add an element of Update Records and label it.
    2. As we update parent fields, select “specify conditions to identify records and set fields individually”.
    3. Select the parent object and filter the records based on the parent’s record Id present in the child object to that of the child’s record.
    4. Choose the field name you want to update, and the value should be the variable name given in the assignment.

Creating the flow when deleting the records:

  1. Log in to the org and go to flows. Click on Create New Flow.
  2. Choose Record Triggered Flow from the “All + Templates” tab.
  3. We need to select when we want this to get triggered.
    1. Choose  “a record is deleted”  to Trigger the Flow
    2. Choose “Action and its related records” to optimise the Flow.
  4. We need to get all the child records associated with a parent record. For this purpose, we need to use the Get Records element.
    1. Give the Label and Name
    2. We need to filter the records based on the Id of the parent’s record present in the child to that of the parent Id.
    3. Get all the records.
  5. We need to loop over the records to perform the operations we need to do.
    1. Use the Loop element and add the “Get Records” API name in the collection variable.
    2. Specify the direction from First Item to Last Item.
  6. We can use the Before delete operation to deduct the pricing value. But what happens is the calculation will not update, and the data will be wrong.
  7. To avoid this issue, we need to capture the sum of all the records for the specified record. Create a variable that stores the value from the child’s record – this operation must be done with the Assignment element.
    1. Give the label and API name for the element.
    2. Create a variable by clicking a new resource and selecting resource type as variable.
    3. Give the variable an API name and currency as data type.
    4. As we need to get the sum of all records for the specified field, choose the operator as ADD.
    5. Assign the value with the field name you need to get the sum from the current loop.
  8. Now that we have the sum of the records, we need to create another Assignment element that subtracts the value of the deleted record from the sum.
    1. Use the same variable.
    2. As we need to get the difference between the computed sum and the deleted record, choose the operator as SUBTRACT.
    3. Assign the value with the field name you need to get the difference from the current loop.
  9. Now here comes the final part of updating the records of the parent object with child field values.
    1. Add an element of Update Records and label it.
    2. As we update parent fields, select “Specify conditions to identify records and set fields individually”.
    3. Select the parent object and filter the records based on the parent’s record Id present in the child object to that of the child’s record.
    4. Choose the field name you want to update, and the value should be the variable name given in the assignment.

Please click on the below link to see the working in action:
Roll-up summary using flows in action

Leave a Comment

Your email address will not be published. Required fields are marked *

Recent Posts

future-of-ai-powered-business-solutions
Dreamforce 2024: Unveiling the Future of AI-Powered Business Solutions
gitex 2024 worlds largest tech show
GITEX 2024 |  World's Largest Tech Show - ABSYZ
inclusive practices in women leadership equitable future
Inclusive Practices in Women’s Leadership: Equitable Future
salesforce dreamfest 2024 the highlights of dreamforce 2024
Dreamfest 2024: The highlights of Dreamforce 2024
DocuSign CLM the ultimate tool for managing contracts
DocuSign CLM: The Ultimate Tool for Managing Contracts
Document

How can i help you? close button

powered     by   ABSYZ
Scroll to Top