
Meet DLRS: The Salesforce Admin’s New Best Friend
Fondly referred to as “Delores” by Salesforce professionals, the Declarative Lookup Roll-Up Summaries (DLRS) managed package was created by Andrew Fawcett, CTO of FinancialForce.com to make your analytical dreams come true. The package is an open-source community application that is constantly improving with each new release. This powerful tool allows the declarative creation of roll-up summaries between loosely related objects with lookup relationships, rather than the usual requirement of a master-detail relationship to create roll-up summary fields.
Salesforce roll-up summary fields allow users to aggregate and summarize data across relationships. In the native version of Salesforce, roll-up summary fields can calculate and display the sum, minimum, maximum, or count of a set of related detail records on a parent record. This can be useful for creating a snapshot of important information, such as total sales or the number of open cases, on a parent account or opportunity record. Roll-up summary fields can only calculate data from child records on the related parent record using master-detail relationships. However, due to several limitations with master-detail relationships, some users will choose to relate objects with a lookup relationship instead.
There are several reasons to opt for a lookup relationship rather than master-detail:
- Sharing and Security Settings: The child object in a master-detail relationship automatically inherits the sharing and security settings of the parent object. Lookup relationships have greater freedom for setting the sharing and security settings.
- Required Attribute: Master-detail fields are always required. Detail records cannot be created without a parent record. Lookup relationships can be variably required. Detail records can be created without assigning a parent record if the lookup field is not required.
- Cascade Delete: Master-detail relationship always cascade delete the detail records when a parent record is deleted. Lookup relationships can be set to cascade delete or keep detail records when the parent record is deleted.
- Record Ownership: In master-detail relationships, the owner of the parent record will always be the owner of the child record. In lookup relationships, the parent record can be owned by a different user than the detail record.
- Detail Standard Object: Master-detail relationships do not allow standard objects to be on the detail side of the relationship. Lookup relationships do not have this limitation.
- Maximum Number of Relationships: A maximum of 2 master-detail relationships can be created per object. Master-detail relationships also have a depth limitation of up to 4 levels from the parent object and 3 levels of rollup summary fields. Additionally, the child of one master-detail relationship cannot be the parent of another. Lookup relationships allow up to 25 relationships per object and do not have the same depth or child-parent limitation.
- Maximum Number of Relationship Fields: Two objects can only have 1 master-detail relationship field. Two objects can have an unlimited number of lookup relationship fields.
While master-detail relationships are necessary in some use cases, there is greater flexibility and available customization for lookup relationships. If the reasons above have convinced you to switch any master-detail relationships to lookups, the fields can be easily converted to lookups by removing any existing rollup summary fields from the parent object and changing the data type of the field to a lookup relationship. It is also recommended to review sharing and security settings after converting any fields to preserve security in the org. Next, we will cover the process of recreating the deleted rollup summary fields using DLRS.
Installing DLRS into a Salesforce org is quick and easy. First, visit the DLRS installation site. Then, log in to a sandbox environment for the org. It is strongly recommended to make any new changes in a sandbox environment to complete testing and prevent any disruptions in production. After logging in via the above link, the installation page allows the choice to install for admins only, all users, or specific profiles. The package then installs 1 app, 9 objects, and 2 permission sets that can be used to provide users access to create lookup roll-up summary fields.
Now it’s time to create a declarative lookup roll-up summary. First, create a lookup relationship between the objects if there is not already one. Next, create a number, currency, or text field to store the rollup value. Finally, navigate to the newly installed Declarative Lookup Rollup Summaries app and select the Manage Lookup Rollup Summaries tab. In the latest release of DLRS (2.17), lookup roll-up summaries can be created using their new wizard by selecting “Try Our New Wizard” and completing the required fields.
First, create a descriptive Lookup Rollup Summary Name and corresponding Lookup Rollup Summary Unique Name. Write a description of the intended use for the lookup rollup summary. Then select the Parent Object from the dropdown list, confirm, select the corresponding Child Object with the new field created above, and confirm. The wizard populates the relationship field for the objects. Next, enter any Relationship Criteria in SOQL Query form to filter the child records to be calculated in the rollup summary field and the Relationship Criteria Fields that are referenced in the Relationship Criteria.
Under Rollup Details, select the Field to Aggregate from the child object and the Aggregate Operation (Average, Concatenate, Concatenate Distinct, Count, Count Distinct, First, Last, Maximum, Minimum, Sum). Then select the Aggregate Result Field to store the results, which is the field created previously in the steps above. The wizard gives the option to Aggregate All Rows, which will include records that are in the recycle bin or that have been archived. If the Aggregate Operation is Last or Concatenate, a Row Limit can be set to only pull a specific number of records. Additionally, for the Concatenate Aggregate Operation, a Concatenate Delimiter can be set to split your concatenated operation. Concatenate Delimiter can be set as “,”, “|”, or BR() for a line break.
The final choices are Calculation Mode and Calculation Sharing Mode. Calculation Mode can be set as Developer to be called from a custom coded Apex trigger, Process Builder which does not require later deployment of the child Apex trigger, Scheduled to calculate at scheduled times, or Realtime which will calculated each time a change is made. Calculation Sharing Mode can be set to run in System context ignoring sharing rules or User context to respect sharing rules.
Finally, for Realtime or Scheduled DLRS configurations, deploy the Apex class and return to check the Active checkbox on the DLRS detail page. For Developer mode, activate the custom trigger and class, then activate the DLRS. For Process Builder, call DLRS from the process builder and activate the DLRS.
With just a few clicks, you have created your first declarative lookup rollup summary! For further support, the official documentation about DLRS can be found here and the GitHub site can be accessed here. DLRS is a community driven open-source tool, so there is not official support available. Any questions about DLRS can be submitted to the DLRS Community Project in Trailhead or on the DLRS GitHub Issues page.
FAQ's
What is DLRS?
DLRS stands for Declarative Lookup Roll-Up Summaries. It is a managed package for Salesforce that allows for declarative creation of roll-up summaries between loosely related objects with lookup relationships.
Who created DLRS?
DLRS was created by Andrew Fawcett, CTO of FinancialForce.com
Is DLRS open-source?
Yes, DLRS is an open-source community application.
What are the benefits of using DLRS?
DLRS offers greater flexibility and customization options compared to using master-detail relationships for roll-up summary fields. It also allows for greater freedom in setting sharing and security settings, and does not have the same limitations on the number of relationships or fields.
How do I install DLRS?
To install DLRS, visit the DLRS installation site and log in to a sandbox environment for your Salesforce org. It is recommended to make any new changes in a sandbox environment first.
Is there any documentation or support for DLRS?
Yes, there is documentation and support available on the DLRS installation site. You can also find additional resources and support within the open-source community.