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
Lavanya Ponniah 3Lavanya Ponniah 3 

Whats wrong in this trigger?Its not firing

trigger OrderInclusiveorWaive on OrderItem (before insert,before update) 
{
    List<Product2> pt = new List<Product2>();
      
    for(OrderItem op : Trigger.new)
    {
        for(PricebookEntry pbe : [Select Id, pricebook2id, product2id, unitprice From PricebookEntry Where Id=:op.PricebookEntryId])
        {
            for(Pricebook2 pb2 : [Select Id From Pricebook2 Where Id=:pbe.Pricebook2Id])
            {
                for(Product2 p : [Select Name From Product2 Where Id =: pbe.product2id])
                {
                       if(p.id == pbe.product2id)
                    {
                        if( op.Inclusive_or_Waive__c ==  TRUE )
                        {
                            if((op.Total_Hardware_Type_Ordered_Products__c) >= (op.Total_Package_Ordered_Products__c))
                              {
                                op.addError(' No Quantity is Matched,Please match it');
                            }
                        }
                        else if( op.Inclusive_or_Waive__c ==  FALSE )
                        {
                            if(p.id!=null || (op.Total_Hardware_Type_Ordered_Products__c) >= (op.Total_Package_Ordered_Products__c))
                            {
                                pt.add(p);
                            }
                        }
                    }
                    update p;
                }
            }
        }       
    }
}
Akshay DeshmukhAkshay Deshmukh
What is the error ? or its just not getting fired?.
Please post some output.
Lavanya Ponniah 3Lavanya Ponniah 3
It's not firing
Akshay DeshmukhAkshay Deshmukh
check if your trigger is active. also are  you trying to insert record of OrderItem ?
It should fire .
Also add System.debug() immedietly before for loop.