Find your content:

Search form

You are here

Validation Error in Production

 
Share

I have written one trigger and it's been working in Production for the last year. Now I have created one more trigger on same Object(Company__c). There is no SOQL statements. Now validate my new trigger in Production at the time old trigger the validation is failing. I got a following validation error:

Error: Failure Message: "System.LimitException: Too many SOQL queries: 101", Failure Stack Trace: "Trigger.DirectCompany: line 8, column 1"

My trigger trigger can handled bulkyfied or not I need to change my trigger?

Old Trigger:

Trigger DirectCompany on Company__c(AFTER INSERT,AFTER UPDATE)  
{

 TRY
 {   
     LIST<Product__c> sapili      = NEW LIST<Product__c>() ;
     LIST<String> orderEstmate = NEW LIST<String>();
     LIST<Product__c> sapiord = [SELECT Id ,Text02__c FROM Product__c WHERE Text02__c !=: '' ORDER BY Id DESC];//LIMIT 50000
     String orderId;

     FOR( Company__c TempOrder  :  TRIGGER.NEW)
     {

          IF(TempOrder.Conform__c == TRUE && TempOrder.Estimate__c.trim() != NULL)
               orderEstmate.add(TempOrder.Estimate__c.trim());
     }            
     LIST<Sub_Product__c> bidproli = [SELECT Id,Name FROM Sub_Product__c WHERE Name IN : orderEstmate];
     FOR( Company__c com : TRIGGER.NEW)
     {      

           IF(com.Conform__c == TRUE && com.Estimate__c != NULL)
           {                                         
               IF(bidproli.SIZE() != 0)  
               {                 
                  String Text2 = '';
                   FOR(Product__c notsapi : sapiord )
                   {
                        Text2 = Text2 + notsapi.Text02__c.trim().substringBefore('|')+', ';
                   }                                    
                   IF(Text2.contains(com.Id))
                   {                         
                       BREAK;
                   }

                   orderId = com.Id;
                   FOR(Sub_Product__c bidpro : bidproli)
                   {                                                  

                        IF(bidpro.Name.Trim().equals(com.Estimate__c.trim())) 
                        {
                                //Here my own logic here
                                sapili.add(sapi);
                                BREAK ;
                        }
                    }
                }  
           }      
     }    
     IF(sapili.size() != 0)
          INSERT sapili;             

 }
 CATCH(EXCEPTION E)
 {
      SYSTEM.DEBUG(E);
 }
}

New Trigger:

Trigger DeleteCompany on Company__c(AFTER INSERT,AFTER UPDATE)
{  
        LIST<Company__c> deletecom  = new  LIST<Company__c>();
        FOR(Company__c order : [SELECT Id,Delete__c FROM Company__c WHERE Id IN : Trigger.NEW])
        {
            IF((order.Delete__c == TRUE))
                deletecom.add(order);
        }   
        IF(deletecom.SIZE() != 0)
            DELETE deletecom;    
}


Attribution to: Ramesh S

Possible Suggestion/Solution #1

Considering this is an After trigger, it wouldn't be a bad idea to add some recursion control in the trigger. Maybe your trigger is executing recursively and therefore hitting the limit.

See this (Taken from the Salesforce KB) http://help.salesforce.com/apex/HTViewSolution?id=000133752&language=en_US

Class code :

public Class checkRecursive{
    private static boolean run = true;
    public static boolean runOnce(){
    if(run){
     run=false;
     return true;
    }else{
        return run;
    }
    }
}


Trigger code :

trigger updateTrigger on anyObject(after update) {

    if(checkRecursive.runOnce())
    {
    //write your code here            
    }

}


Attribution to: PepeFloyd
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/34428

My Block Status

My Block Content