+ Start a Discussion
Kristen Aldrich 14Kristen Aldrich 14 

Flow throwing errors - CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY: SVT_OpportunityTrigger: System.LimitException: Too many SOQL queries: 101

When I run a particular flow in our Partial Sandbox (Lightning), I get the following errors:
  • FIELD_FILTER_VALIDATION_EXCEPTION: Value does not exist or does not match filter criteria.
  • UNABLE_TO_LOCK_ROW: unable to obtain exclusive access to this record or 165 records. 
  • CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY: SVT_OpportunityTrigger: System.LimitException: Too many SOQL queries: 101.
I think the first one is a matter of checking related lookup filters on applicable fields in the objects utilized in the flow. The second one I don't know what it means. The third one is something wrong with my Trigger (set up by a consultant), but I don't know Apex all that well.

Can someone help with one or all of these error issues? Here's the Apex Trigger code for the third error:
 
trigger SVT_OpportunityTrigger on Opportunity (before insert, before update, before delete, 
                                after insert,after update, after delete, after undelete) {
    //System.debug('Before Trigger Control------> ');
    TriggerSettings__c control = TriggerSettings__c.getOrgDefaults();
    if(!control.OpportunityTrigger__c)
    {

        SVT_OpportunityTriggerHandler handler = new SVT_OpportunityTriggerHandler(Trigger.isExecuting, Trigger.size);
        SVT_OpportunityHandler opportunityHandler = new SVT_OpportunityHandler();
        /*
        SVT_OpportunityTriggerHandler.hasBeenCalled = true;
        
        if((Trigger.isBefore&& Trigger.isUpdate)||(Trigger.isAfter && Trigger.isInsert)||(Trigger.isAfter && Trigger.isUpdate)){
            OpportunityHandler.newSObjectMap = Trigger.newMap;
            OpportunityHandler.SObjectIds = Trigger.newMap.keySet();
        }
        
        if(Trigger.isUpdate || Trigger.isDelete){
            OpportunityHandler.oldSObjectMap = Trigger.oldMap;
            OpportunityHandler.oldSObjects = Trigger.old;
        }
        
        if(Trigger.isInsert || Trigger.isUpdate){
            OpportunityHandler.newSObjects = Trigger.new;
        } */
        
        handler.handler = opportunityHandler;
        
        if(Trigger.isInsert && Trigger.isBefore){
        //  System.debug('Trigger Before Insert Check');
            handler.onBeforeInsert(Trigger.new);
        }else if (Trigger.isInsert && Trigger.isAfter){
            //System.debug('Trigger After Insert Check');
            //try{
            handler.onAfterInsert(Trigger.new, Trigger.newMap, Trigger.newMap.keySet());
            If(!System.isBatch()) SVT_OpportunityTriggerHandler.onAfterInsertAsync(Trigger.newMap.keySet());
          //  OpportunityLineItemTriggerHandler.onAfterInsertAsync(Trigger.newMap.keySet());
            //}catch(Exception ex){
                //System.debug('Error: '+ ex.getMessage()+'. ON LIne: '+ ex.getLineNumber()+'. Stack Trace: '+ ex.getStackTraceString());
        //  }
        }else if (Trigger.isUpdate && Trigger.isAfter){
            //System.debug('Trigger After Update Check');
            handler.onAfterUpdate(Trigger.new, Trigger.old, Trigger.newMap, Trigger.oldMap,Trigger.newMap.keySet());
           // OpportunityLineItemTriggerHandler.onAfterUpdateAsync(Trigger.newMap.keySet());
        }else if (Trigger.isBefore && Trigger.isUpdate){
            //System.debug('Before Update Trigger Check');
            handler.onBeforeUpdate(Trigger.new, Trigger.old, Trigger.newMap,Trigger.oldMap, Trigger.newMap.keySet());
        }else if (Trigger.isBefore && Trigger.isDelete){
            //System.debug('Before Delete Trigger Check');
            handler.onBeforeDelete(Trigger.old, Trigger.oldMap);
        }else if (Trigger.isAfter && Trigger.isDelete){
            //System.debug('After Delete Trigger Check');
            handler.onAfterDelete(Trigger.old, Trigger.oldMap);
        }else if (Trigger.isUndelete){
            //System.debug('Undelete Trigger Check');
            handler.onUndelete(Trigger.new);
        }
        //added by Aman    -- COmmented out by PR 12/19/2017. This is purely for launch. Remove this ASAP.
  /*     if((trigger.isafter && trigger.isinsert) || (trigger.isafter && trigger.isupdate)){
         try{
            SVT_OpportunityHandler.CreateContactFromOpp(trigger.new,trigger.newmap,Trigger.newMap.keySet());
            }catch(Exception ex){
                System.debug('Error: '+ ex.getMessage() +'. Stack Trace: '+ex.getStackTraceString());
            }
            
        }  */
    }
}
Naveen KNNaveen KN
Hi Kristen, 

Salesforce supports 100 SOQL queries within a transaction. From the error, we can find that SOQL in a transaction is exceeding the limit. 

check the developer console > log section to find which part of the code is having more queries and optimize the code based on that

- Naveen
Kristen Aldrich 14Kristen Aldrich 14
Hi Naveen, 
Thanks for that assistance. I'm not sure how to find or interpret my debug logs. I went to the Developer Console and then to the Log section. I'm not sure how to search my logs from yesterday. I wound up executing the flow again this morning to hopefully find and review the logs more easily but am not sure I'm looking in the right place. Can you provide more instruction?