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
subodh chaturvedi 17subodh chaturvedi 17 

System.LimitException: Too many SOQL queries: 101 :- this Method i am calling in trigger:- please help me where i am wrong


      Public static Void  territoryFinancialsDj(List<Territory_Plan__c> tpe){
           Set<Id> ownerIds =New set<Id>();
           List<Event> evtList = new List<Event>();
           List<Territory_Plan__c > ObjectRec = new List<Territory_Plan__c >(); 
           List<Territory_Plan__c > tpList = new List<Territory_Plan__c >(); 
           List<Territory_Plan__c > ObjectBList = new List<Territory_Plan__c >(); 
            List<Opportunity> oppoList = new List<Opportunity>();
  
           For(Territory_Plan__c t:tpe){
               ownerIds.add(t.Account_Executive__c);
           }
           
           Map<Id, Opportunity> oppoMap = new Map<Id, Opportunity>([SELECT Id, StageName, ownerId FROM Opportunity WHERE OwnerId IN : ownerIds]);
           evtList = [SELECT Id, WhatId, Status__c, Type, ownerId FROM Event WHERE Status__c='Completed' AND Type='On-Site at PSCU' AND ownerID IN:ownerIds ];
               for(Territory_Plan__c tp:tpe){
                               for(Event e: evtList){
                   if(tp.Account_Executive__c==e.ownerId && oppoMap.containsKey(e.WhatId) && tp.Account_Executive__c==oppoMap.get(e.WhatId).ownerId){
                       oppoList.add(oppoMap.get(e.WhatId));
                     
                   }
               }    
             tp.of_Onsite_at_PSCU_YTD__c = oppoList.size();
               tpList.add(tp);
               
           }
           
      }
      
Amit Chaudhary 8Amit Chaudhary 8
Hi,

You above code look good to me. Please check debug log and check your trigger is becoming recursive any where ? if yes then you need to stop that with the help of Static variable
shailesh_rawteshailesh_rawte
Hi,

Could you share your trigger code.


 
subodh chaturvedi 17subodh chaturvedi 17

Guys this is my trigger Code 
trigger TerritoryPlanDetails on Territory_Plan__c (Before Insert,After Insert,After Update,Before Update) {
    if(Trigger.isBefore) {
       if(trigger.IsInsert){
       territoryPlanDetailsUpdate.territoryFinancialsDj(trigger.new);
      
   }
    }
    if(Trigger.isBefore) {
       if(trigger.IsUpdate){
       territoryPlanDetailsUpdate.territoryFinancialsDj(trigger.new);
   
       }
    }