I have a parent-and-child-object scenario. The parent will have a TOTAL field and the child a VALUE field. I want to show a total of all child VALUES on the parent.
I can either do that with a Master/Detail and use a roll-up summary field or a Lookup and a workflow or trigger to do the calculations I guess.
The reason I'm considering workflow / Apex trigger is that I may want to control the security of both objects independently. However, I realise that using workflow / trigger I will need to recalculate the total each time, meaning I have to grab all children, manually code the calculations, etc…
What are the pros / cons of both approaches?
Best Answer
The pros and cons list for rollup summary vs trigger is pretty short. In fact, you've taken care of most of the pros and cons of using a rollup summary in your question.
Rollup Summary:
Pros:
Cons:
Rollup via Trigger:
Pros:
Cons:
There are a few different ways to accomplish a rollup via trigger
[SELECT SUM(Field1__c) FROM myCustomObject__c]
Personally, when I need to use a trigger to do a rollup, I favor using a SOQL query to do the heavy lifting. Doing it via SOQL takes care of most of the null checks, and saves writing the same boilerplate summing logic over and over.
The declarative rollup summary tool is probably the best choice for most people outside of using a standard rollup summary field. I haven't used it myself, and don't know how well it would play with various trigger frameworks.
Conclusion:
In your case, the decision probably comes down to the question of how likely you are to need to manage the security of both objects independently.
If you will need to manage them independently, or think it's quite likely you will need to someday, go with a trigger rollup (looking at the declarative rollup summary tool first). Putting your two objects into a Master-Detail relationship would leave you with a technical debt that would be hard to resolve.
If their security can be managed together, and it doesn't look like that will ever change, go with the standard rollup via Master-Detail relationship.