You need to sign in to do that
Don't have an account?
AwkwardA
System.LimitException: Too many SOQL queries: 101
I'm getting the "Too many SOQL queries" error on Line 17. Help me troubleshoot?
trigger InsideSalesAppointment on Task (after insert, after update) { Map<Id,Date> LeadsToUpdate = new Map<Id,Date>(); List<User> InsideSalesUser = [SELECT Id FROM User where UserRoleId='00E30000001rctV']; Set<Id> InsideSalesUserId = new set<Id>(); for (User u :InsideSalesUser) { InsideSalesUserId.add(u.Id); } for (Task t: Trigger.new) { if(InsideSalesUserId.contains(t.OwnerID) && t.IsClosed == false && String.valueOf(t.WhoId).startsWith('00Q') && t.WhoId != NULL) LeadsToUpdate.put(t.WhoId, t.ActivityDate); } List<Lead> LeadsAppointment = [SELECT Id FROM Lead where Id IN:LeadsToUpdate.keyset()]; if (LeadsToUpdate.keyset().size()>0){ for (Lead l: LeadsAppointment) { l.Next_Appointment_Date__c = LeadsToUpdate.get(l.id); } update LeadsAppointment; } }
All Answers
Here's the test class:
The above solution looks good. Also, do check your debug in details as there can be a scenario that triggers are getting executed again and again. If above solution does not work for you then you need to add a helper class with a static boolean variable so that trigger fire only once .
Thanks