I currently have an object called Opportunities__c
with a child object related to it, Opportunities_Forecast__c
via a Master-Detail relationship. The Forecast__c
object contains two number fields that ultimately get summed up using a Roll-Up Summary field on the Opportunities__c
object.
The nature of the object needs to change now in that Opportunities_Forecast__c
is just a general forecasting object and could be related to the Account
object or Opportunities__c
object, thus it may not always have a relationship to an Opportunity__c
record. I know Master-Detail fields are required on child objects, so I have to change the data type to a Lookup.
I can't do this (yet) because of the Roll-Up summary fields. So, I was wondering what the best way to handle the functionality of Roll-Up summary fields, without them being Roll-Up summary fields.
One idea I had was to use a Trigger that would check for Create, Update and Delete events and recalculate the fields accordingly, but I was wondering if there was a better way to do this.
Best Answer
The standard go-to answer is to use Andrew Fawcett's excellent Declarative Rollup Summary package. There's a managed package install link, and it comes complete with a UI for configuring your desired rollups. It works on any object that supports custom fields and triggers, so give it a go! Also, it's open source, so you can borrow bits and pieces if you decide to give it a go yourself. Finally, this has definitely been answered here on SFSE before, including an answer of my own. The actual implementation is pretty trivial when you get down to it, but you do need to pay attention to the details.