Overcoming Rollup Summary Limitations in Salesforce with LREngine
Rollup summary fields are a common requirement in Salesforce implementations 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, developers must write an apex code to roll up the child information for common aggregations like COUNT, SUM, AVG, MAX/MIN, etc. Some of these situations are
Only ten rollup summary fields are 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(Create, Update, Delete/Undelete) events on child sobject. These triggers manually aggregated the information via Apex or used SOQL Aggregate queries.
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
Update 2020
References
Official Repo on Github > https://github.com/abhinavguptas/Salesforce-Lookup-Rollup-Summaries
Feature in official Salesforce Blog > A Declarative Rollup Summary Tool for Force.com Lookup Relationships - Andrew Fawcett.