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.
Apex Trigger
to calculate the summed up value. The trigger context will be on insert, update and delete.