Rollup Summary with Flow

Rollup Summary with Flow

Rollup Summary with Flow

Introduction:-

Roll-up summary fields are one of the most useful custom field types in Salesforce, but not when your object model is based on lookup relationships. You see this magic only works on objects which are related as master detail.

Now we use ProcessBuilder and Flows to achieve the Rollup Summary with Lookup Relationship. 

Use Case:-

Let’s go with a very simple object model Project with a lookup to Account.

Follow these steps:

Step 1 :

  • Create a Custom object(Ex: Project) Which is having lookup relation with Account.
  • Create a Custom Field (Number)  on Account.

Step 2: Create a Flow

Under the Data section Drag and drop the Get Records Enter the Label and Description Under Get Records of this Object Select the Project object.

And meet the condition with the Account field on a project to variable CurAccountID variable(Text) by creating a variable in flow. 

In How Many Records to Store Select the All Records.

Check the Manual assign variables(advance)  Option ,Create a new Collection variable 

Click on Done.

Step 3:

Drag and drop the Loop in the logic section of the flow

Fill up the label and select the collection variable as {!curAccountProjects}

Create a Loop variable which can store the project record in the loop

Select the loop variable which is created {!Project} and click on Done 

Link the Elements as shown in the figure above: 

Step 4:

Drag and Drop Assignment under the Logic section in Flow

 Fill up the label and Description sections 

Create a variable with a data type number  and a Decimal value is 0

Map the variables  as shown in the figure above:

Map the Elements as shown in the figure below: 

Step 5: 

Now we have to update the Current Account record field Total Projects with Loop variable Drag and Drop the Update Records from the data section in Flow. Select options as shown in the figure below

Link the Update Record Element as shown in the Figure below:

Step 6: Create ProcessBuilder 

Now Create a Process builder on the Project object and  select the Action Type to Flow with no Criteria   and pass the Project’s AccountID

Conclusion:

By following the outlined steps, you can successfully implement Rollup Summary functionality for lookup relationships in Salesforce. This approach enhances flexibility and empowers users to effectively manage data relationships across various object models, ensuring a more comprehensive and streamlined Salesforce experience.