Salesforce Development: Apex

Salesforce Open Source MVP’s: How to use James Simone’s Rollup Application

4 min read

Subscribe on YouTube

A New Series: Salesforce Open Source MVPs

This is the first episode of a brand new series, and I want to explain why I’m starting it.

There are so many genuinely great free open source applications and libraries for Salesforce that almost nobody seems to know exist. DML mocking frameworks, the Apex Common Library, and the application we’re covering today.

If more of the community knew about these, I think two things would happen. First, we’d all have better and more unified codebases. Second, a fair few managed packages would cease to exist and people would save a lot of money.

So the goal here is simple: show these things exist, and give the authors a platform to be recognised and to demonstrate how their work actually functions.

And I’ve been lucky enough that James Simone, author of the excellent Joys of Apex blog, agreed to come on and show us his application, Rollup.


The Problem It Solves

Salesforce gives you roll-up summary fields, which are lovely. They’re also hemmed in by a set of restrictions everybody eventually runs into:

1. Master-detail relationships only. Lookups don’t get them, which rules out a huge amount of real data models.
2. A hard cap per object. You get a limited number and busy objects run out.
3. No filtering beyond the basics. Complex criteria are out.
4. No cross-object arithmetic or anything genuinely clever.

So you hit one of those walls and your options are: write your own rollup Apex (which is more work than it sounds, especially bulkified and handling deletes and reparenting), or buy a managed package.

Rollup is the third option, and it’s free.


What Makes It Good

It works on lookups. This is the headline feature and the reason most people install it.

It’s configured with Custom Metadata. Which means adding a new rollup is a config record, not a deployment. An admin can do it. This is exactly the Open/Closed Principle applied properly: extending it means adding data, not editing code.

It handles the hard cases. Reparenting, deletes, undeletes, bulk operations. These are precisely the scenarios that make hand-rolled rollup code go wrong, and they’re all covered.

It scales. It’ll run synchronously, or move to Queueable or Batch automatically depending on volume, so it doesn’t fall over when somebody bulk loads 200,000 records.

The test coverage is excellent. James takes testing seriously, which given this is going to sit in the middle of your data integrity is exactly what you want.


How You Use It

Install it from the repo (there are unlocked package links in the README), then create a Rollup__mdt record describing what you want:

Calc Item – the child object you’re rolling up from
Lookup Object – the parent you’re rolling up to
Rollup Field On Calc Item – the child field being aggregated
Rollup Field On Lookup Object – where the answer goes
Rollup Operation – SUM, COUNT, MAX, MIN, AVERAGE, CONCAT, FIRST, LAST
Calc Item Where Clause – optional filtering

Then either add a one-line invocation to your trigger, or drive it from a Flow. Both are supported.

Note that CONCAT, FIRST and LAST aren’t things native roll-up summaries can do at all. “Show me a comma separated list of every open case subject on this account” is a genuinely common request that has no declarative answer.


When To Use It, And When Not To

Don’t use it when a native roll-up summary field works. Native is maintained by Salesforce, calculated by the platform, and costs you nothing to look after. Always try that first.

Do use it when you’re rolling up across a lookup, you’ve run out of native rollups, you need filtering the native ones can’t express, or you need an operation Salesforce doesn’t offer.

And if you’re currently paying for a managed package that does only this, it’s worth an afternoon evaluating whether Rollup covers your cases. For a lot of orgs, it does.


The Honest Caveats

It’s not calculated by the platform. Native rollups are maintained by Salesforce itself. This is Apex running in your org, consuming your governor limits.

You’re depending on a community project. James maintains it well and has for years, but it isn’t a Salesforce product with a support contract. Read the code before you install it, which you can, because it’s open source.

There’s a learning curve on the metadata. The configuration is powerful and correspondingly fiddly. Budget a bit of time.

None of those are reasons not to use it. They’re just things to know going in.


Go And Support This Stuff

Genuinely, thank you to James for building this and for keeping it open source when he could easily have packaged it up and charged for it.

Go and star the repo, read the Joys of Apex blog (it’s one of the best technical Salesforce blogs going), and if you find a bug, raise an issue rather than working around it silently.

More open source MVPs to come in this series.


Get Coding With The Force Merch!!

We now have a redbubble store setup so you can buy cool Coding With The Force merchandise! Please check it out! Every purchase goes to supporting the blog and YouTube channel.

Get Shirts Here!
Get Cups, Artwork, Coffee Cups, Bags, Masks and more here!


Check Out More Coding With The Force Stuff!

If you liked this post make sure to follow us on all our social media outlets to stay as up to date as possible with everything!

Youtube
Patreon
Github
Facebook
Twitter
Instagram


Salesforce Development Books I Recommend

Advanced Apex Programming
Salesforce Lightning Platform Enterprise Architecture
Mastering Salesforce DevOps

Good Non-SF Specific Development Books:

Clean Code
Clean Architecture