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
Saniya Khan 2Saniya Khan 2 

I want to update a Lead and team member object depending upon some condition on before update trigger but its working perfectly for on e record and fails for more than 100 records

Hi All,
I want to update a Lead and team member object depending upon some condition on before update trigger   but its working perfectly for on e record and fails for more than 100 records showing too many SOQL records on line 23 here is my code

public class AllocateTeamMemberHandler {
    
 public static void allocateTeamMember(List<Lead> leadList)
    {
        set<id> LeadId=new Set<id>();
        Map<id,Lead> LeadMap=new Map<id,Lead>();
        Map<id,Team_Member__c> TeamMap=new Map<id,Team_Member__c>();
        List <Team_Member__c> updateTeamMember=new List<Team_Member__c>();
       Boolean Flag=false;
        for(Lead uplead:leadList)
        {
            if(uplead.Allocate_Team_Member__c!=false)
            {
                System.debug('I am in 1st Lead for loop');
                LeadId.add(uplead.OwnerId);
                LeadMap.Put(uplead.OwnerId,uplead);
                flag=true;
            }
        }
        if(flag!=false)
        {
            System.debug('I am in If ');
        List<Team_Member__c> teamMemberList=[Select id, User_ID__c, Queue_ID__c, Last_Allocated__c, Availability__c from Team_Member__c where Queue_ID__c IN :LeadId and Availability__c = 'Yes' ORDER BY Last_Allocated__c ASC limit 1];
            System.debug('Size of Team List is'+teamMemberList.size());
        For(Team_Member__c team:teamMemberList)
        {
            System.debug('I am in team for loop');
            updateTeamMember.add(new Team_Member__c(Id=team.id,Last_Allocated__c=System.now()));
            TeamMap.put(team.Queue_ID__c,team);
        }
        For(Lead changLead:leadList)
        {
            if(TeamMap.containsKey(changLead.OwnerId))
            {
                System.debug('I am in if of 2nd Lead for loop');
                changLead.OwnerId=TeamMap.get(changLead.OwnerId).User_ID__c;
                changLead.Allocate_Team_Member__c=false;
            }
        }
        if(updateTeamMember.size()>0)
        {
            update updateTeamMember;
        }
      } 
      }
}
Could anyone please help me wuth this..
Many Thanks,
Saniya
Steven NsubugaSteven Nsubuga
In your Apex trigger, ensure that you call the class like this:AllocateTeamMemberHandler.allocateTeamMember(trigger.New);
Saniya Khan 2Saniya Khan 2
Thanks for your reply Steven, but I am calling my class that way alrady still have that issue
Niraj Kr SinghNiraj Kr Singh
Hi Saniya,

Can you plz share your trigger as well...
Saniya Khan 2Saniya Khan 2
trigger AllocateTeamMember on Lead (before update) {
if(Trigger.isUpdate)
  {
     
        AllocateTeamMemberHandler.allocateTeamMember(Trigger.New);
  }
    
}