function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jeff TalbotJeff Talbot 

line item trigger not firing with opportunity delete

I have a custom object "Inventory Movement". On Opportunity Line Items, I have a custom lookup field that links the Line Item record to an "Inventory Movement" record. If the Line Item is deleted, the Inventory Movement record needs to be deleted.

I have successfully implemented an "after delete" Trigger on Opportunity Line Items. When I delete an Opportunity Line Item, the Trigger deletes the Inventory Movement record.

I'm not clear why my trigger doesn't work when I delete an Opportunity. When an Opportunity is deleted, its line items are automatically deleted by Salesforce system functionality. How come this auto deletion of line items doesn't fire the Trigger?
Best Answer chosen by Jeff Talbot
GlynAGlynA
DML performed as a result of some automation functions, such as cascade deletion in this case, do not fire triggers.  The solution is to move your Inventory Movement logic into a class that can be invoked by both the Opportunity Line Item trigger and the Opportunity trigger.  When an Opportunity is deleted, query its Opportunity Line Items and pass those to the Inventory Movement logic as if they had been deleted already (which they will be soon enough).

Glyn Anderson
Sr Developer | System Analyst | ClosedWon | closedwon.com
Certified Developer | Certified Advanced Administrator
Twitter: @GlynAtClosedWon