Roll-Up Summary for Account Fields (Part 2)

Part 2 to: Roll-Up Summary for Account Fields (Part 1)

Flow #2 Breakdown

We are going to create a Flow that will find if the parent account.  If the Account has a ParentId, we want to then query all of the accounts under that Parent and summarize the Amount of Chicken sold for each child.  After we summarize that data, we will then update the Parent Account with the new value.  This will allow us to update all levels of a hierarchy on an Account with one simple Flow, because this Flow will keep being triggered until it reaches the Parent Account.

Lets get Started!

Create a New Flow.  (Setup | Create | Workflows & Approvals | Flows)  

For this Flow we need to create two Text Variables, called AccountId and ParentId.

AccountId

ParentId

Create a Currency Variable called Amount_of_Chicken_Sold.  

Amount of Chicken Sold Variable

Create one SObject Variable called Collected_Account and one SObject Collection Variable Collection_Of_Accounts.  Note – these must be associated to the object you are planning to do the query for.  An SObject Collection Variable is the group of records you have returned back, and the SObject Variable is one of those records.

Collected Account

Collection of Accounts

Does your Explorer tab look like this?

Roll-Up Summary part 2 explorer

If yes, lets start to build out the Flow!

Create a Record Lookup called “Find the ParentId”

Find the ParentId

Now we want to find out if there is a Parent Record associated to this Account.  The purpose, is so that we will know if we need to fire the Flow or not.  You could do a filter like this in your Process Builder, but I like to keep it all in one location when possible.

Is there a Parent?

Create a Fast Lookup to get the collection of Accounts that have this ParentId


Fast Lookup for Accounts Collection

Now we want to create a Loop to go through all of the Child Accounts that we just collected in our Fast Lookup.

Loop through Child Accounts

Now we want to create an Assignment to calculate the Total of all the Child Account’s Amount of Chicken Sold.

Add up Chicken Sold

Now that we have Looped through all of the records to find the new Total Amount of Chicken Sold for this Parent Account’s Children, we want to add it to the value on the Parent.

Create a Record Update to finish the Flow.

Update the Parent Account

Now we need to connect our elements together!  Note, the Assignment element goes back to the Loop.  When you connect the Loop to the Assignment element, you want to select the “for each value in the collection”.  Also, don’t forget to mark the First Record Lookup as the Start element!

Loop Routing for Parent Roll-UpsParent-Child Completed Flow

Great Job!  You finished the Flow!  Now lets save it and then Activate it!

Saving the Parent Roll-Up

Now we need to make a Process Builder to fire off our Autolaunched Flow.  The Process Builder is going to be based on the Account Object.

Account Based Process Builder

We will create the Criteria for firing the Flow, and choose to only fire it when the Amount of Chicken Sold’s value has changed.

Parent Roll-up PB Criteria

Create the Immediate Action “Flows” and select the Flow we just activated.  Map the AccountId variable to the [Account].Id value.

Parent Roll-up Add Flow

Congratulations! You are ready to activate your Process Builder and see your awesome Roll-Up Summary in action!

Leave a comment