I have a 1-to-many relationship using a lookup. I have a trigger that does a rollup on the parent object. So, anytime a child record is inserted, updated or deleted, the trigger fires and updates the master with the new rollup total. It works perfectly. However, there is a field on the parent object that if changed, needs to re-run the rollup of the child objects. What is the best approach to do this?
Also, I have another issue with a master-detail relationship, that the master record being deleted does not fire the child records delete via a cascade delete? How can I get the trigger to fire on the child object when the master is deleted?
Thanks for any help.
Best Answer
On the rollup question only...
This is a case where it is probably worth factoring out the code that does the rollup into a separate class. That then allows the triggers to be fairly simple:
and sharing most of the code: