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
RDN_LHRRDN_LHR 

Can I cause Trigger to fire only before delete called from UI?

I currently have a "before delete" trigger on OpportunityLineItem which stops line item records from being deleted if certain conditions are met.

 

Is there a way use an if to say that if the delete call is coming from the API or is due to a delete on the parent Opportunity record, to ignore the steps in the trigger?  I'd only want the steps to execute if the trigger is called from a line item delete via the UI.

 

I thought I read this once somewhere, but after all my searching, I can't seem to find it. 

 

Anybody know?

 

Thanks!!

Best Answer chosen by Admin (Salesforce Developers) 
HarmpieHarmpie

Usually you would solve this by surrounding your effective trigger code by if(Trigger.new.size() == 1) { // Triggercode }.

 

This assumes the API never is used for only 1 record at once.

Message Edited by Harmpie on 05-04-2009 02:11 AM

All Answers

aalbertaalbert
What about a custom button (still labeled Delete) on the Opportunity Products related list or page layout. That button calls a Visualforce page that invokes Apex code to validate the delete is allowed and if so, performs the delete. Otherwise, the Visualforce page can display the proper notification message.
HarmpieHarmpie

Usually you would solve this by surrounding your effective trigger code by if(Trigger.new.size() == 1) { // Triggercode }.

 

This assumes the API never is used for only 1 record at once.

Message Edited by Harmpie on 05-04-2009 02:11 AM
This was selected as the best answer