dlrs in Salesforce | Lookup Rollups | SalesforceTutorial

Written by Prasanth Kumar Published on Updated on

Dlrs is a community-maintained Salesforce package for rollups across lookup relationships. Use it when a standard roll-up summary field is not available, but a parent record still needs a stored count, sum, minimum, maximum, average, or filtered total from child records.

What is dlrs in Salesforce?

DLRS means Declarative Lookup Rollup Summaries. It lets admins define rollup metadata instead of writing a new Apex trigger for every lookup relationship. A rollup definition identifies the parent object, child object, lookup field, aggregate field, operation, result field, criteria, and calculation mode.

Salesforce standard roll-up summary fields are designed for supported master-detail relationships. For lookup relationships, teams usually evaluate Salesforce Flow automation, custom Apex, an AppExchange package, or dlrs. In enterprise orgs, the choice depends on data volume, sharing, deployment control, and how quickly the parent value must update.

When should you use dlrs?

Use dlrs when the rule is stable, the relationship is lookup-based, and admins need to maintain the calculation without editing code. Do not use it for every reporting need. If users only need the value in a report, a report summary may be enough. If the value drives validation rules, routing, segmentation, approvals, or integrations, a stored parent field can be justified.

Salesforce dlrs setup checklist

  • Parent object: the object that receives the value, such as Account.
  • Child object: the object being counted or summarized, such as Opportunity.
  • Relationship field: the lookup field on the child, such as AccountId.
  • Aggregate field: the child field used in the calculation. Use Id for counts.
  • Result field: the parent field that stores the value. Create it before configuration.
  • Criteria: the filter that includes or excludes child records.

Declarative lookup rollup summaries fields

Declarative lookup rollup summaries still require the same thinking as an aggregate SOQL query. Decide which child records qualify, how to group them by parent, which aggregate operation to run, and where to write the result.

Setting Purpose Check
Parent object Receives the rollup value. Confirm the result field owner and FLS.
Child object Stores related records. Review record volume and existing automation.
Relationship field Connects child to parent. Test old-parent and new-parent recalculation.
Operation Count, sum, average, min, or max. Match field type to operation.
Criteria Filters child records. Use selective fields where possible.

Dlrs salesforce calculation modes

The current package documentation describes Realtime, Watch for Changes and Process Later, Invocable by Automation, and Developer modes. Older versions may use labels such as Scheduled or Process Builder. Record the package version and calculation mode in your release notes.

Mode Use when Risk
Realtime The parent value must update immediately. Extra save-time work can affect CPU, SOQL, and locks.
Watch for Changes and Process Later Imports or integrations update many child records. Jobs and queued records need monitoring.
Invocable by Automation Flow should decide when the rollup runs. Automation order and recursion must be tested.
Developer Apex should call the calculation. Developers own tests and error handling.

How to configure a dlrs rollup safely

  1. Create the parent result field and set field-level security.
  2. Write the rollup rule in plain language before using the package UI.
  3. Configure the parent object, child object, relationship field, aggregate field, operation, and criteria in a sandbox.
  4. Select a calculation mode after reviewing data volume and stale-data tolerance.
  5. Deploy any required child trigger only after checking existing triggers and flows.
  6. Run a full recalculation after setup, data migration, criteria changes, or result field changes.
  7. Test insert, update, delete, undelete, lookup reassignment, bulk import, and restricted-user access.

Example: sum closed won opportunities on Account

A common salesforce dlrs use case stores total closed-won opportunity amount on Account. Configure parent object Account, child object Opportunity, relationship field AccountId, aggregate field Amount, operation Sum, result field Closed_Won_Amount__c, and criteria IsWon = true.

Example: count open cases on Account

Another fit for declarative lookup rollup summaries is counting open cases. Use child object Case, relationship field AccountId, aggregate field Id, operation Count, and criteria IsClosed = false. Test open-to-closed, closed-to-open, delete, undelete, and account reassignment.

DLRS vs Flow vs Apex: which option should you choose?

Option Best fit Watch out for
Standard roll-up summary Supported master-detail relationships. Not a general lookup solution.
DLRS Admin-managed lookup rollups. Package dependency, generated triggers, scheduled jobs, and upgrades.
Flow Small-volume process-specific calculations. Deletes, bulk updates, and query efficiency.
Apex High-volume or complex logic. Developer ownership, tests, limits, and maintenance.

Apex alternative for a lookup rollup

This bulk-safe Apex pattern shows what dlrs helps avoid writing repeatedly. It uses one aggregate SOQL query and one DML update list. Replace Closed_Won_Amount__c with your target field.

public with sharing class AccountOpportunityRollupService {
    public static void rollupClosedWonAmount(Set<Id> accountIds) {
        if (accountIds == null || accountIds.isEmpty()) return;
        Map<Id, Decimal> totals = new Map<Id, Decimal>();
        for (AggregateResult row : [
            SELECT AccountId accountId, SUM(Amount) totalAmount
            FROM Opportunity
            WHERE AccountId IN :accountIds AND IsWon = true
            GROUP BY AccountId
        ]) {
            totals.put((Id) row.get('accountId'), (Decimal) row.get('totalAmount'));
        }
        List<Account> updates = new List<Account>();
        for (Id accountId : accountIds) {
            updates.add(new Account(Id = accountId, Closed_Won_Amount__c = totals.containsKey(accountId) ? totals.get(accountId) : 0));
        }
        update updates;
    }
}

Custom Apex must include tests for insert, update, delete, undelete, and parent lookup changes. Salesforce requires Apex tests to pass and code coverage requirements to be met for production deployment.

Security and performance best practices for dlrs

  • Set field-level security on the parent result field because a stored value can reveal child-record information.
  • Choose user-based or system-style calculation deliberately in private data models.
  • Use Realtime carefully because it shares transaction limits with other automation.
  • Use delayed processing for large imports or integration loads.
  • Monitor rollup logs, scheduled jobs, and package upgrades.

Common errors with DLRS and how to troubleshoot them

Symptom Likely cause Fix
Parent value is blank Wrong API name, no matching children, or no recalculation. Verify API names and run a controlled recalculation.
Value is too high Criteria includes extra records. Add explicit status, record type, date, or active filters.
Works for admins only Sharing or FLS differs by user. Test with real permission sets.
Bulk load is slow Realtime work runs inside the import transaction. Switch to delayed processing.

Official Salesforce references for rollup design

DLRS is a community-maintained package, not a native Salesforce feature. For package behavior, review DLRS Documentation and the DLRS GitHub repository. For platform behavior, use Salesforce documentation:

For related topics, see SOQL query examples, Salesforce reports and dashboards, Salesforce Flow automation, and Data Loader bulk import planning.

Frequently Asked Questions

What is dlrs used for in Salesforce?

dlrs is used to calculate values from child records and store the result on a parent record when the relationship is a lookup.

Is Salesforce dlrs a standard Salesforce feature?

Salesforce dlrs is not a native platform feature. It is a community-maintained package, so use Salesforce documentation for platform behavior and package documentation for setup.

Can declarative lookup rollup summaries replace Apex triggers?

Declarative lookup rollup summaries can replace many simple aggregate triggers. Use Apex when the calculation needs complex branching, custom locking, or strict engineering control.

Should I use Realtime or scheduled processing in dlrs salesforce implementations?

Use Realtime when the parent value must update immediately and volume is low. Use delayed processing for imports, integrations, or high-volume updates.