I have a hole in the logic of a huge Trigger that "piggybacks" data from Opportunities to Account (summarized). If someone touches an Opp, this trigger fires and checks ALL OPPS under that Account for "that Product" (a field on the Opp) and summarizes the data into 5-10 fields on the Account.
Issue: I do not have proper logic in place so that if an Opp is deleted, this Trigger would fire and do "it's normal job" when that was the ONLY OPP for that Product. It works fine if at least one Opp still exists for that product.
Logic tells me that I need to run an "after delete" trigger which would run THIS TRIGGER, but the problem is, this trigger requires an Opp (at least one) to work with. If no Opp exists, this Trigger would do nothing.
The fields that could be affected vary depending on what options are selected for that Product. I'm fearful that I may need to write a cut-down version of the trigger JUST FOR After Delete to clear all fields if NO Opps exist for that Product any longer (a LOT of new territory for me - including how to reference in an After Delete fields on the record just deleted...). I could probably just encapsulate said logic in an ELSE where the original trigger is the IF THEN (1+ opps exist, ELSE do cleanup routine).
Any ideas? The entire basis of this 500 line trigger is that one or more Opps exist (for the product in question), but I need it to cleanup up (basically NULL) the data for that Product on Account if the one and only Opp for that product is deleted.