Skip to content

Rollup Architecture

James Simone edited this page Oct 11, 2021 · 2 revisions

Architecture Diagram

Best viewed via this link or by clicking the image: Apex Rollup Architecture diagram

High-Level overview

apex-rollup is broken into two distinct sections, by default:

  • the operations performed synchronously
  • the operations performed asynchronously (unless RollupControl__mdt.ShouldRunAs__c is set to SYNCHRONOUSLY)

The operations that run sync are primarily marshalled by Rollup - this class is the backbone of the application, as well as its primary entrance point (the sole exception being RollupFlowBulkProcessor and RollupFlowBulkSaver, which are delegates that call into Rollup itself).

All instances of Rollup have a member list, rollups of type List<RollupAsyncProcessor>: an actual rollup operation that is cleared to run asynchronously will also be of type RollupAsyncProcessor. The "outer" rollup, or "rollup conductor" is either:

  • an instance of Rollup - it has no inner rollups; its rollups list is empty, and no asynchronous operation is performed

  • an instance of RollupAsyncProcessor, whose inner rollups can have many different forms:

    • RollupAsyncProcessor - the most standard type; each instance creates a RollupCalculator and runs through the appropriate rollup calculation
    • RollupFullBatchRecalculator - uses Database.Batchable to create the equivalent of a for loop for a given set of rollup operations
    • RollupDeferredFullRecalcProcessor - essentially a Queueable version of RollupFullBatchRecalculator
    • RollupParentResetProcessor - a specialized subclass of RollupFullBatchRecalculator that resets parent-level values when there are no children records for a given parent or set of parents

    RollupAsyncProcessor itself has two different implementations:

    • the outer class is a Database.Batchable implementation, for when the number of parent records retrieved would exceed the limit defined by RollupControl__mdt.MaxLookupRowsBeforeBatching__c
    • RollupAsyncProcessor.QueueableProcessor which is the default implementation, unless RollupControl__mdt.ShouldRunAs__c is tweaked. Acts the same as the outer class's batchable implementation, but as a queueable instead