Use Case: Create Custom Roll-Up Summary With Flow

I have really mixed feelings about the roll-up summary field. The concept saves us so much time when taking care of related objects, but due to the limitation on the filter, we often can’t achieve all that we want. Of course, there are some nice apps (Ex. Rollup Helper) but sometimes I can’t get them to work properly. So let’s turn to our old pal, Salesforce Flow!

Lulu Mobile uses standard Opportunity and Opportunity Product objects to track their deals. A customer might commit to a multiple-year contract, but to them, the more important measure is the first year‘s value so they can have a more accurate case flow forecast. They also only want to include the main services – phone subscription or internet subscription in the calculation, as other services are usually from third-party providers.

Limitation Of Roll-up Summary

You can only put the actual date in the standard roll-up summary field filter, which is not fitting our requirements here because each Opportunity has a different date. You cannot customize the logic of the filters, so it always uses AND to connect all filters. Lastly, the roll-up summary only works on a master-detail relationship. These can all be resolved with flows.

Limitation Of Flow Solution

However, we will have some other issues. Ideally, we should trigger the flow to recalculate when an Opportunity Product (child record) is created, updated, or deleted. However, in the Record-Triggered flow, the create/update (upsert) trigger is different from the delete trigger.

We can instead create a roll-up summary first to count how many Opportunity Products there are, and trigger the flow to recalculate when the count changes. However, the flow will then only fire when create and delete, but not update. (Since the count does not change)

That means, in either way we will have to build two flows to handle this question:

  1. Build two record-triggered flows on Opp Products, one fire on create/update and one fire on delete.
  2. Create a roll-up summary on Opportunity to count Opp Products, and a checkbox to indicate when products are updated. Build one record-triggered flow on Opportunity to fire when count changes. Build one record-triggered flow on Opp Products to fire on update.
Solution Comparison

Solution 1 is a lot easier to build (The two are basically the same flows with a different trigger), however, it will trigger the flow the same times as the number of modified records. If you always have a lot of child records, this can be very harmful to your instance! Only use this method when the actions are simple and the number of child records is small.
Solution 2 on the other hand can be a lot more efficient and can handle complex actions, but it is complicated to build. We will use Solution 2 in this article.

Lastly, flow might not be the best tool for this case, look for the possibilities of using good apps or APEX first, then use flow as the last resort.

Flow 1: Update Opportunity When Opp Product Is Edited

flow roll-up summary - flow#1

Flow 2: Main Flow – Launch when Opp Product Created/Deleted or Edited

flow roll-up summary - flow#2

Please wait while flipbook is loading. For more related info, FAQs and issues please refer to DearFlip WordPress Flipbook Plugin Help documentation.

Record-TriggeredAssignmentVariable and Collection
DecisionUpdate RecordsLoop
Get RecordsFormula

Does the solution solve your problem? If not, write us what your problem is and we will build the flow for you!

Official Salesforce Help Article On Flow

Subscribe
Notify of
guest
3 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Bidtravel

Nice! There is also this awesome tool called DLRS possible to install as managed package. With it you can make roll ups of any object but you can also get values like text and filter them to include them all or only unique ones, arrange them and many more. I am wondering if with lightning flow you could achieve the same.

BIDtravel

As simple as that, thanks!