+ Start a Discussion
The new LearnerThe new Learner 

getting too many soql error--urgent

Hi Experts,

I have requirement i need to update the task owner once lead owner changes for me its working but getting too many soql errors when i chek debug log i am getting lot of records including my record , can anyone help me please, my trigger is after insert and after update which is on lead object.

 Map<Id, Lead> leadMap = new Map<Id, Lead>([Select Id, OwnerID from Lead where Id IN: Oldmap.keyset()]);
         system.debug('++++owners'+leadMap );
         
         
          for(Task tsk:[select id,OwnerID,Whoid from task where whoid in :leadMap.keyset()])
          {
           system.debug('++++tsk'+tsk); 
           Id owner=leadMap.get(tsk.whoid).ownerid;
           system.debug('++++owner'+owner);
           id test=leadMap.get(tsk.whoId).id;
            system.debug('++++test'+test);
            if(!leadMap.containskey(tsk.ownerid) &&  tsk.whoid !=null && leadMap.containskey(tsk.whoId) && !string.valueOf(owner).startsWith('00G') && leadMap.get(tsk.whoId).id==tsk.whoid )
            {
              tsk.ownerid=leadMap.get(tsk.whoid).ownerid;
              system.debug('++++owners'+tsk.ownerid);
              oldtasks.add(tsk);
              system.debug('++++tasks'+oldtasks);
            }
            }
            update oldtasks;
            system.debug('++++'+oldtasks); 

 
The new LearnerThe new Learner
my error is "System.LimitException: Too many query rows: 50001"
Raj VakatiRaj Vakati
You can do one thnik 


 Map<Id, Lead> leadMap = new Map<Id, Lead>([Select Id, OwnerID from Lead where Id IN: Oldmap.keyset()]);


in the abouve Query insted of doing for all old map owners check the changed onwers between old and new owner and they try