DLRS (Declarative Lookup Roll-up Summaries) is an important managed package for building roll-up summaries between lookup relationships.
The open-source tool provided by Andy Fawcett makes defining roll-ups using standard user interface declaratively easy.
What Makes Roll-Up Summaries Difficult between lookup relationships?
It is possible to create roll-up summary fields for a variety of purposes.
As an example, if you realize that two objects you want to create a roll-up summary field between are related via a lookup relationship instead of a master-detail relationship, you can create it.
- A Master-Detail Relationship allows the creation of roll-up summary fields.
- Lookups are not possible.
Using roll-up summaries with Salesforce is limited, but there are other options:
- Creating an Apex trigger is the ‘traditional’ way to do it. For declarative (low-code) administrators and consultants, this isn’t a good option. By involving a developer, you may end up with the extra hassle and a project that exceeds your budget;
- Salesforce Flow is a useful tool;
- Declarative Lookup Roll-up Summaries (DLRS): The tool was developed by Andy Fawcett from the Salesforce community as an open-source project.
What is Declarative Lookup Roll-up Summaries?
DLRS provides low-code professionals with the ability to create a roll-up summary between two objects in a lookup relationship without writing any code.
You must install a managed package into your organization in order to access the configuration.
How to Use DLRS?
It takes some time to get used to DLRS. Using it a few times, you will see how the interface and fields deconstruct Apex triggers (that magic happens behind the scenes).
With the App Launcher, you can access DLRS (waffle icon, top-left).
Three tabs are available:
➛ Create and update Lookup Rollup Summaries;
➛ Search for errors in the Lookup Rollup Summary Logs;
➛ Lookup Rollup Summaries Tools: Make your automation more efficient with Optimizer, which recommends improvements to how it is configured.
- The DLRS calculates the roll-up summary based on all records related to the parent record, so there are no criteria to be respected.
- It’s not a typical example (using two of our custom objects), but you can replace them with your own.
- The total number of clicks from all places where the advertisement appears (on our website and in emails) is calculated. Master object = Adverts, child object = Advert Spaces.
- Create a new Declarative Roll-Up
- Parent object: insert the API name of the object (head to object manager to find this). Do the same for the child object.
- Relationship field: The API name of the relationship field should be inserted on the child object, i.e. the field that references the parent.
- A field that will be aggregated: The field from which the calculation will be based, for example, the amount, clicks, or score.
- Choose from Sum, Avg, Count, and other aggregate operations (this is similar to the “Select Roll-up Type” section of a standard roll-up summary setup).
- Aggregate Result Field: The field where the calculated value should be inserted. The custom field would be one you created beforehand.
- Calculation Mode: Choose whether you want DLRS to run Real-time (whenever a child record is updated), Scheduled (when records are collected and executed in batches), Developer (to run DLRS yourself), or Process Builder (to call a DLRS record directly). Real-time is typically chosen for small datasets and scheduled for heavily-used objects.
- Calculation Sharing Mode: Select a user or a system. A calculation will be made based on the access rights of the user who triggered the DLRS. All records are visible to the system.
Click “save”, deploy the child trigger, then run a full calculate job.