Cloud for Good
Search
Close this search box.

Declarative Lookup Rollup Summaries: An Admin’s Must-Have Tool

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: