Roll-Up Summary for Account Fields (Part 1)

You are hit with some tough demands from someone inside your organization. They want to be able to click on an Account and see the dollar amount of widgets their clients have sold, and be able to see that value on each level of the hierarchy.  Well, this throws Roll-Up Summary fields out the window!  Unfortunately they do not want to use a report to do this, so we need to create an Autolaunched Flow to calculate this for them.

Keep in mind

  1. Flows are triggered by Process Builder and that limits them from triggering BEFORE they are deleted.  So, if your company is deleting Accounts and Opportunities often, then you might need to build a recalculate button (coming soon!).
  2. Standard Roll-Up Summary fields do not go up and down the hierarchy.  They only work for one record.
  3. Standard Roll-Up Summary fields are formula based, and do not allow us to do Record Updates.  You could use one in the Flow, but I prefer to use as few fields as possible and will create a custom Currency Field to be the value we use.
  4. We will be creating TWO Flows and TWO Process Builders (to trigger our Flows).  The main purpose of this is that we can accomplish the hierarchy Roll-Ups with a smaller Flow and have it work for any number of parent-child relationships.

Flow #1 Breakdown

We are going to create a Flow that will find all Won Opportunities associated to an Account.  Every time an Opportunity is Won, with the Opportunity Type of Chicken, we want to update the custom Roll-Up Summary field on the Account.

Lets get Started!

On the Account create a Currency Field with 2 decimals called Amount of Chicken Sold (Setup | Customize | Accounts | Fields).

Create Amount of Chicken

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

Lets start with the variables we need to create for this Flow.

Two Text Variables, called OpportunityId and AccountId

Create an Opportunity Id

AccountId

One Currency Variable, called Opportunity_Amount

Create Opp Amount

Two SObject Variables, called Collected_Opportunity and Collected_Child_Account

SObject Variable Opportunities

SObject Variable Accounts

Two SObject Collection Variables, called Opportunity_Collection and Child_Accounts_Collection

SObject Collection for Opportunities

SObject Collection for Accounts

Does your Explorer tab look like this?

Roll-Up Summary part 1 explorer

If yes, lets start to build out the Flow!

We will start with a Record Lookup.  We want to grab the Account Id using the Opportunity.

Find the Related Account

Add a Fast Lookup element so that we can create a collection of all the Opportunities associated to this Account, with our filter criteria (IsWon = True and Type = Chicken).

Fast Loopup Opportunity Collection

Create a Loop element for us to go through the collection of Opportunities and add the values together.

Opportunity Loop

Create an Assignment element to add up the value of every Opportunity this Account has that meets our filter criteria.

Add Opportunity Values

Lets connect the elements we have created now.  Assign the Assignment element to the Loop and set the first Record Lookup as the Starting element

Flow 1 part 1

Now that we have our first set of loops set.  We need to query for the possibility of any Child Accounts that might have Opportunities with Chicken being sold.

Fast Lookup for Accounts Collection

Create a Loop element for us to go through the collection of Accounts

Loop through Child Accounts

Now we need to do add every Child Account’s Chicken Amount to the Opportunity_Amount variable.  This will allow us to get the total value of all the Opportunities associated to this Account and the Child Accounts.

Assignment of Child Accounts

Only one more element to go for this Flow!  We need to create a Record Update to put the correct Amount of Chicken Sold on the Account.

Update the Account

To finish this Flow off, we now need to connect the elements we just built and save the Autolaunched Flow.

Flow #1 Completed Save the Flow #1

To fire off an Autolaunched Flow, we must create a Process Builder.  We want this Process Builder to fire off the Opportunities so that we can have it update the Roll-Up Summary field anytime a change happens.

Process Builder for Flow 1

We want every Opportunity to pass through this Flow, because we have our filter on the Fast Lookup.

Process Builder for Flow 1 part 2Process Builder for Flow 1 part 3

Now activate the Process Builder.  Congrats on finishing Part 1 of the Roll-Up Summary!  Part 2 will allow us to make sure all levels of the hierarchy are updated when an Amount of Chicken Sold value changes.

One thought on “Roll-Up Summary for Account Fields (Part 1)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s