August 18, 2012

Creating easy rollup summary fields in salesforce

Rollup summary fields are pretty common requirement in customizations and app development. Rollups are easy to create on master-detail relationships as they are available as a field type. But on certain limits/situations we need to write apex code for rolling up the child information for common aggregations like COUNT, SUM, AVG, MAX/MIN etc, some of these limitations are

The 'USUAL' approach to handle this limitation is to either

  • Write trigger on various DML(reate, Update, Delete/Undelete) events on child sobject. These trigger either manually aggregated the information via Apex or used SOQL Aggregate queries for the same.
  • Write some batch/scheduled apex to perform this nightly.

I tried solving this problem by creating a small apex utility called “LREngine”. Complete description and details about it are available here on github: