Written by Cloud for Good Team
Rollup summaries are great things to have in your admin toolkit. With a rollup summary, you can summarize information about child records on a parent record when those records are in a master-detail relationship. Want to see how many gifts a corporate partner has given in the last three years? Rollup summary! Want to see how many campaign members there are in a campaign? Rollup summary!
Want to see how many times a Contact has been a part of a Campaign? Want to roll that information up to the Account level? Standard rollup summaries arenβt going to do you any good here. They depend on having master-detail relationships between objects, and those objects have lookup relationships instead. Uh-oh.
Andrew Fawcett, CTO of FinancialForce.com, Salesforce MVP, and all-around superhero, created a fantastic package to handle situations just like these. Allow me to introduce you to the Declarative Lookup Rollup Summary Tool, sometimes known as DLRS, and more affectionately known (at least at Cloud for Good) as Delores–sounds sort of like DLRS, right?
The Declarative Lookup Rollup Summary Tool expands upon Salesforceβs native rollup summary functionality to let admins quickly and easily create rollup summaries based on lookup relationships in a declarative way. The tool is free, painless to install, and guides admins step-by-step through how to build their first rollup with extremely well-made help text. There arenβt many implementations I do that donβt take advantage of DLRS–so many of my clients need the level of functionality it provides!
To get started, youβll need to think through a few things:
- First, what do you want to roll up? Make sure that a relationship between the two objects exists already. If one doesnβt, create it.
- Next, what kind of summary are you hoping to see? DLRS supports a wide variety of SOQL-powered operations: Sum, Max, Min, Average, Count, Count Distinct, Concatenate, Concatenate Distinct, Return First, and Return Last. Which of these operations best fits your use case?
- Are there any records you will want to exclude? For example, if youβre trying to count a number of major gifts a donor has made, and your organization defines a major gift over $1,000, youβll want to filter out any records under that amount.
- How quickly do you need this data? Will you need to see it the moment you save a record, or can it recalculate in a nightly job? If you need it right away, it might make saving records take just a little bit longer. If the rollup doesnβt need to be updated immediately, setting it to run on a schedule might be a little more friendly to your users.
- Finally, make sure that your rollup has a place to go! This will typically mean creating a field to store your rollup, so make sure thatβs in place before you try to build your rollup summary. Donβt use an existing field unless you want DLRS to overwrite existing data in that field.
Once you have a sense for what youβre going to build and where itβs ultimately going to live, then itβs time to get building!
The easiest way to build a Lookup Rollup Summary is by using their relatively new enhanced builder. If youβre creating a rollup for the summary for the first time, itβs a little hidden; you can only see the βEnhanced New Lookup Rollup Summary (Pilot)β button from a list view in the Lookup Rollup Summaries tab. Donβt let the fact that itβs pilot functionality scare you. It works like a charm. Give that button a click!
After clicking the button, youβll be brought to a very friendly Visualforce page that will guide you step-by-step through declaratively configuring your rollup.
Youβll of course want to give it a descriptive name that you (or someone who needs to edit the Lookup Rollup Summary later) will recognize.
In the βParent Objectβ field, select the parent object. This is going to be where you ultimately see the rollup summary after all is said and done. Select the field you built to store your rolled-up data from the βAggregated Results Fieldβ picklist.
In the βChild Objectβ section, select the child object and field linking the two objects together. You might very well see the same object listed here more than once if there is more than one lookup relationship joining the objects together. For example, if youβre creating a Lookup Rollup Summary where Accounts is the parent object, and youβre trying to roll up completed Tasks related to a given Account, youβll need to use the βWhatIDβ relationship between the two. If youβre working with a standard object and arenβt sure which field to use, the Salesforce API documentation about that object can be very helpful. The best way to find that is to search for it online with the name of the object, Salesforce, and βAPI documentationβ.
Make sure to specify the operation youβre looking for in the βAggregate Optionβ picklist, and pick the field to aggregate on the child object with the βChild Field to Aggregateβ picklist.
Finally, if you have any filter criteria, you need to write the WHERE portion of a SOQL query that would filter out these records. Salesforceβs documentation on the topic is extremely helpful, and you can test what youβve written in Workbench to make sure it works. Be sure that you include the API names of the fields youβre using in your filter in the βRelationship Criteria Fieldsβ field, separated by line breaks.
Once all of that information is in, hit βSaveβ, and youβre done! If you selected a βRealtimeβ Calculation Mode, the rollup summary will run every time someone makes a change that would change the rollup value. If you want to set a baseline, open up the new Lookup Rollup Summary record and click βCalculateβ, which will make it the tool run on every record that might need to be evaluated.
While the Declarative Lookup Rollup Summary Tool is just about perfect, there are a few gotchas that might just get you if you arenβt careful.
First, if youβre trying to use the count operation, you need a field to count! Because itβs always on a record, you might think to use the ID field, but sometimes that might not work out well technical SOQL stuff thatβs beyond the scope of this article. Thereβs an easy fix, though! Create a formula field on the child object. I generally call it βTallyβ. The formula should be β1β — just that, nothing else. This will create a new field on your object with a value that is always β1β. You can then use that as the field you count, which will make your rollup tick up by one every time itβs successfully rolled together. Piece of cake!
Finally, make sure that anybody who will be interacting with fields might be rolled up by the Declarative Lookup Rollup Summary Tool are given the βLookup Rollup Summaries – Process Rollupsβ permission set. Otherwise, theyβll see a nasty error when they try to save a record thatβs affected by DLRS.
With those caveats out of the way, youβve got this — now get rolling!
Looking for something else to read? Consider: