I'm trying to build a trigger between Accounts and Orders. I've already built the trigger and made it to work but wanted to confirm my understanding.
Requirement: The Sum of Order Amounts should be reflected on Accounts every time a order is added/deleted.
My obsevation: adding a Order (under a Account) creates an empty Order with 0 in Total Amount. Only when you add Order Product, does the amount get reflected in Orders. But, the after insert/update trigger on Order object is unable to get the value for Order Amount (for the record being inserted/updated). To resolve this, I've created an after insert/update trigger on OrderProduct and I'm now able to access the OrderAmount and the totals are correct. However, the same doesn't work for after deletes/undeletes on OrderProduct. The trigger is not detecting the 'cascaded deleted of the child OrderProduct' when the parent Order is deleted (which I assumed it will). So, I had to write another trigger explicitly to track the delete/undelete actions on Order object to be able to add up the OrderAmounts correctly.
Please confirm if I'm missing something with the way Order is behaving or OrderProduct is behaving. Is there anyway I can solve this just 1 triggers - be it either on Order or OrderProduct object.