The Declarative Lookup Roll-Up Summaries (DLRS) managed package is a must-have for creating roll-up summaries between lookup relationships. Andy Fawcett’s open-source tool is a gift, enabling you to define roll-ups using standard UI declaratively, no coding required!
This guide will cover the high-level details, plus a couple of example use cases. First, let’s outline the challenge you need to solve.
Why Roll-Up Summaries Between Lookup Relationships are Challenging
You will encounter many use cases for creating roll-up summary fields. Getting stumped, mid-way through configuring, is so frustrating. One example is realising that the two objects you want to create a roll-up summary field between aren’t related via a master-detail relationship – they are related via a lookup relationship. The horror!
- Master-detail relationship: possible to create roll-up summary fields.
- Lookup relationship: not possible…
…or so you may think. Sure, standard Salesforce functionality limits what’s possible with roll-up summaries, but there are other options to fulfil your requirement.
- Write an Apex Trigger: the ‘traditional’ route. This isn’t a friendly option for declarative (low-code) admins and consultants. Involving a developer could result in extra hassle, and in a project, reaches into your budget.
- Use Salesforce Flow
- Declarative Lookup Roll-Up Summaries (DLRS): an open-source tool developed by Andy Fawcett from the Salesforce community. Let’s explore DLRS for Salesforce some more…
What is Declarative Lookup Roll-Up Summaries (DLRS)?
DLRS enables low-code professionals to create a roll-up summary between two objects in a lookup relationship, without having to touch any code. To access the configuration, a managed package is installed into your org.
How to Use DLRS
DLRS does take some getting used to. After using it a couple of times, you will begin to see how the interface and the fields included deconstruct Apex triggers (that magic happens behind the scenes).
DLRS is accessed via the App Launcher (waffle icon, top-left).
You’ll find three tabs:
- Manage Lookup Rollup Summaries: create new, and update existing roll-ups.
- Lookup Rollup Summary Logs: find errors when the summaries run.
- Lookup Rollup Summaries Tools: access Optimizer, which recommends improvements for how your automation is configured to make it more efficient.
Head to the “Manage Lookup Rollup Summaries” tab. The “Select Lookup Rollup Summary” dropdown shows both a ‘create new’ option, and all previous declarative roll-ups you created (this can throw new users off).
Simple DLRS Example
A simple DLRS calculates the roll-up summary based on all records related to the parent record – in other words, no criteria that should be respected (you will see the differences in the ‘complex’ example later).
The example I’m going to walk through isn’t common (using two of our custom objects) but replace the object names with your own.
Example: calculate the total clicks from all spaces that display the advert (on our site and emails). Master object = Adverts, child object = Advert Spaces
Throughout setting up a DLRS, I recommend you keep Object Manager open on a different tab for easy and quick reference.
Note: the following steps are reflected in the image below.
1. Create a new declarative roll-up
2. Parent object: insert the API name of the object (head to object manager to find this). Do the same for the child object.
3. Relationship field: insert the API name of the relationship field on the child object, ie. the field that ‘looks up’ to the parent record.
4. Field to aggregate: the field the calculation will be based on, eg. amount, clicks, score, etc.
5. Aggregate operation: choose from Sum, Avg, Count, and other options (this reflects the “Select Roll-Up Type” section in standard roll-up summary setup):
6. Aggregate result field: the field where you want to insert the calculated value. This would be a new custom field you created beforehand.
7. Calculation mode: choose whether you want DLRS to run in Real-time (whenever a child record is updated), Scheduled (where records are collected into batches, then executed), Developer (have free reign to call DLRS from your own Triggers/Classes), or Process Builder (call a DLRS record from PB). Typically, you would choose Real-time for small datasets and Scheduled for heavily-used objects.
8. Calculation sharing mode: choose User or System. User respects sharing rules, the calculation will be based on the access the user who triggered the DLRS has. System has visibility into all records.
9. Click “save”, deploy the child trigger, then run a full calculate job (note: choose your timing wisely for heavily-used orgs with large datasets of the child records – or risk slowing your org’s performance down!) you can add clauses to run the job only for specific records.
10. Any failed roll-ups will be shown in the Rollup Summary Logs tab.
Complex DLRS Example
Now let’s look at adding criteria into the mix. Criteria tells DLRS which related child records to include (and therefore exclude) in the roll-up summary calculations.
Again, the example isn’t common (using two of our custom objects) but replace the object names with your own.
Example: calculate the number of content for a contact, only including content with a ‘published’ status. Master object = Contact, child object = Content
- Repeat steps 1-6 from the simple example. Notice this time the aggregate operation is Count, as I simply want the total number of related records; the field to aggregate is simply ‘Id’.
- Relationship criteria: write a statement to define which records should be included eg. Status__c = ‘Published’ (you can apply this formula to any picklist field)
- Relationship criteria fields: specify which fields are included in the criteria you outlined about, eg. Status__c
- Continue with steps 7-9 from the simple example.
Get Support, and Get Involved with DLRS
This overview has only scraped the surface of what’s possible with DLRS for Salesforce. If this has interested you, then you should explore further into the tool.
Join the Trailblazer Community group with like-minded DLRS fans; not only can you get your tricky questions answered, you may find some inspiration for future roll-ups!
Read about the future of DLRS, from the creator, Andy Fawcett.
To continue to grow it needs more attention than I can give it. If you are interested in keeping it open source and becoming a lead developer for it – let’s chat! 🙏🏻 👍🏻 #dlrs @SalesforceDevs
— Andrew Fawcett (@andyinthecloud) July 2, 2021
Read more:
- 4 Ways to Create Rollup Summary Fields on Lookup Relationships in Salesforce
- How to Create Roll-Up Summary Fields in Salesforce with Rollup Helper
- Create Roll-Up Summary Fields Using Salesforce Flow
Comments: