I have a trigger on the Opportunity that fires BeforeInsert & BeforeUpdate. Among other things, one of the requirements of the trigger is that a specific field on the opportunity is updated if an OpportunityLineItem with a product family of X is deleted and a different field is updated if an OpportunityLineItem with a product family of Y is deleted.

SOQL cannot query deleted OpportunityLineItems. I looked at the Database.GetDeleted function, but that is throwing an unexpected error. Google isn't showing anything relevant.

So, is it possible to determine which (if any) OpportunityLineItem was deleted in a trigger on the Opportunity? I cannot use a trigger on the OpportunityLineItem.

Thank you!

  • As adding a trigger to OpportunityLineItem would solve the problem straightforwardly, perhaps you can explain why that solution isn't possible for your situation.
    – Keith C
    Nov 4, 2014 at 18:23
  • I need to be able to perform other tasks in the Opportunity trigger BeforeUpdate/BeforeInsert. Having a trigger on both would be recursive, right?
    – Optimus
    Nov 4, 2014 at 18:26
  • Yes updating Opportunity from an OpportunityLineItem trigger will cause your Opportunity trigger to run. But that is not an unusual situation, and may require no extra logic. If unwanted work is done, static guard variables or only checking for specific field changes in the Opportunity trigger can be used to reduce that work.
    – Keith C
    Nov 4, 2014 at 18:37
  • 1) create a custom field in Opportunity called OpportunityLineitem_Delete_Log__c, (2) afterdelete trigger on OpportunityLineItem appends or smashes (depends on your appl logic) OpportunityLineitem_Delete_Log__c perhaps as a JSON string of the relevant fields you want to examine; (3) After update Opportunity trigger examines OpportunityLineitem_Delete_Log__c and does what you need.
    – cropredy
    Nov 4, 2014 at 22:52


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.