Rollup summary fields are pretty common requirement in force.com 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
- Only 10 rollup summary fields allowed per object on master detail relationships
- Rollup child sobject records part of a lookup relationship. Native rollup summary fields are not available on LOOKUP relationships.
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: https://github.com/abhinavguptas/Salesforce-Lookup-Rollup-Summaries