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
Tom Ford 15Tom Ford 15 

apex trigger no longer firing

Hi,
I've inherited a Sales Cloud org, that until recently had the following trigger working. Now the Original Total Cost is no longer populated at the trigger points.
However the Error at deletion is still being sucessfuly fired.
 
trigger OLITrigger on OpportunityLineItem (before insert, before update, before delete) {
    
 //Code block to enable bypassing of triggers using field off users record  
    String currentUserId = UserInfo.getUserId();
    User currentUser = [SELECT Bypass_Triggers__c FROM User WHERE Id = :currentUserId LIMIT 1];
    if (currentUser.Bypass_Triggers__c) return;
        
    If(System.Trigger.isInsert){
    
      For(OpportunityLineItem oli: Trigger.New){
    
        oli.Original_Total_Cost__c = oli.TotalPrice;
        
      }
  }
    
  If(System.Trigger.isUpdate){

       For(OpportunityLineItem oli : [SELECT TotalPrice,Original_Total_Cost__c,Opportunity.StageName FROM OpportunityLineItem Where Id IN: Trigger.New]){
           
      if(oli.Opportunity.StageName == 'Closed Won')
     {
         //Do Nothing
     }
           
      else  if(Trigger.oldmap.get(oli.id).TotalPrice == Trigger.newmap.get(oli.id).TotalPrice)
           {
               // Do nothing  
            }
                  
     else if(Trigger.oldmap.get(oli.id).TotalPrice != Trigger.newmap.get(oli.id).TotalPrice)
     {
          oli.Original_Total_Cost__c = Trigger.oldmap.get(oli.id).TotalPrice;
     }
       }
  }
       
  If(System.Trigger.isBefore &&System.Trigger.isDelete){
    
  For(OpportunityLineItem oli : Trigger.old)
    {
        if(oli.number_of_invoice_lines__c == 0 || oli.number_of_invoice_lines__c == null){

        list<Line_Item_Details__c> LineItemDetailsId=[Select Id FROM Line_Item_Details__c Where id =:oli.Line_Item_Details__c];     
        delete LineItemDetailsId;
        }
        
        else if(oli.number_of_invoice_lines__c >= 1) 
        {
            oli.addError('You can not delete this Product as it has Invoiced Schedules');
        }
       
    }
    }

}

 
@anilbathula@@anilbathula@
Hi Tom,

The original cost gets updated when there is a change in Total price.
Make sure the total price is updated on the record ,other wise it will enter to the first else if condition and do nothing.

Thanks
Anil.B
Tom Ford 15Tom Ford 15
Thanks Anil, but the trigger isn't even firing at Insert nor when the Total Price is changed 
SAGAR BAWANESAGAR BAWANE
http://www.shayaripe.com/2020/04/best-sad-life-status-shayari-in-hindi.html
http://www.shayaripe.com/2020/04/cool-style--status.html
http://www.shayaripe.com/2020/04/funny-shayari-in-hindi.html
http://www.shayaripe.com/2020/04/Sad-emotional-status.html
http://www.shayaripe.com/2020/04/love-status-or-quotes-in-hindi.html
http://www.shayaripe.com/2020/04/romantic-whatsapp-status.html
http://www.shayaripe.com/2020/04/royal-attitude-status-in-hindi_19.html
http://www.shayaripe.com/2020/04/i-love-you-in-marathi-status.html
http://www.shayaripe.com/2020/04/new-love-shayari-in-hindi.html
http://www.shayaripe.com/2020/04/sad-shayari-in-hindi.html
http://www.shayaripe.com/2020/04/Hindi-Shayari-Image.html
https://www.shayaripe.com/2020/04/new-love-shayari-in-hindi.html
http://www.shayaripe.com
<a href="https://www.shayaripe.com">love shayari</a>
SAGAR BAWANESAGAR BAWANE