Rollup Summary with Flow

Rollup Summary with Flow

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 Projects with lookup to Account.

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 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 condition with Account field on 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 2:

Drag and drop the Loop in the logic section of flow

Fill up the label and select 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 3:

Drag and Drop Assignment under Logic section in Flow

 Fill up the label and Description sections 

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

Map the variables  as shown in the figure above:

Map the Elements as shown in the figure below: 

Step 4: 

Now we have to update the Current Account record field Total Projects  with Loop variable

Drag and Drop the Update Records  from data section in Flow.

And select options as shown in the figure below

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

Step 5: Create ProcessBuilder 

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