How to setup Declarative Lookup Rollup Summary

A long time ago I fell in love with Declarative Lookup Rollup Summary aka DLRS. It allows me to do things which are impossible to do with standard rollup summary fields and I also don’t have to write any code.

Actually, when I saw it for the first time I was scared. I found the UI not intuitive enough and rather choose Rollup Helper, even thought that solution is limited for three rollups (if you don’t want to pay anything).

But than came the moment when I really needed a few more and I realised it is pretty easy to setup DLRS. At least I thought at that time, even though I didn’t really took any advantage of all the things it offers.

What it does and why to use that?

Let’s start with that it does It calculate values from all related record. The standard rollup fields work only on Master-Details relation and cannot really handly any time-based calculations.

DLRS can handle any type of relations, can run on schedule which means time-based calculations are possible, and can also „roll-up“ text fields, meaning it can create for example a comma separated list of all related contacts. And that’s pretty handy.

Why not use trigger?

Of course you can use trigger to achieve anything you want. The problem is that it is a code you need to write PLUS when you change the calculation you need to update all records to recalculate it.

The beauty of DLRS is, that when you update your calculation you can just re-run it and have updated values without any extra work.

Why not use process builder and flow?

Of course you can use flow to do the calculation, even Salesforce provides you an example. The super important point is at the end – „This solution does not run on record delete.“

How it works?

You just install the app from the link (or more detail explanation how to install it) and define the configuration for each rollup you need. One such example below, you just specify the objects, relationship field, criteria and which field you want to sum into which one?

Save and either schedule or deploy a trigger and run it in real time.

DLRS definition of calculation

And here is the trick I found after many years. I mean you cannot do anything wrong about scheduling or running real time, you can just do better and here is what you need to know.

DLRS is surprisingly clever. It doesn’t have to process all records in scheduled mode – as I always thought – it can process only subset of them. Those which were changed. And if I got it right, this is how you should do it.

Full calculate

Select Process Builder mode (doesn’t really make sense as you don’t have to use PB at all, but whatever) and click Schedule Calculate. You can set your WHERE clause on parent object if you want to limit it, set dates/times and you are good, nothing else need as DLRS will do everything for you.

Incremental Calculate

Maybe you have plenty of record and the recalculation takes for ever (like the custom written scheduled class I have in one org which runs for the whole day).

In such case you will deploy the trigger (with Manage Child Trigger button) and you will set the mode to Scheduled, because realtime probably doesn’t make sense or you don’t really want to run it realtime. Then you will manually schedule the RollupJob class to which time you want and at that time it will process ALL scheduled tasks to do.

Zajímá mě tvůj názor