You need to sign in to do that
Don't have an account?

Too many SOQL queries: 101
Hello
I know this usually happens when you have your SOQL in a loop. However in the code below I do not see this. The code is below. I have highlighted the line of SQL in Question.
trigger UpdateFieldsFromLogMeeting on Task (after insert, after update) {
SingletonResource singleton = SingletonResource.getInstance();
Id callRecId = singleton.callRecId;
Id meetingRecId = singleton.meetingRecId;
Id faceRecId = singleton.faceToFaceRecId;
Id prospectRecId = singleton.prospectRecId;
Id candidateRecId = singleton.candidateRecId;
Id sysAdminId = singleton.sysAdminId;
list<Id> ContactIds = new List<Id>();
list<Id> OwnerIds = new List<Id>();
System.Debug('Go through tasks');
for(task t : Trigger.new) {
ContactIds.add(t.WhoId);
System.Debug('Task Owner: ' + t.OwnerId);
OwnerIds.add(t.OwnerId);
}
//------------------------------------------------
map<id,contact> contacts = new map<id,contact>();
for(task record:trigger.new) {
if(record.whoid!=null&&record.whoid.getsobjecttype()==contact.sobjecttype) {
contacts.put(record.whoid,null);
}
}
contacts.putall([select Id,Phone,FirstName,Email, EAR_Assist__c, EAR_Assist_Name__c, EAR_Validate__c, EAR_Validation_Date__c, LeadSource, EARAssistTask__c from contact where id in :contacts.keyset()]);
//------------------------------------------------
map<id,contact> contactstoupdate = new map<id,contact>();
Map<Id,User> users = new Map<Id,User>();
for(User u : [Select id, Name, UserRole.Name from User u where u.id in :OwnerIds]) {
System.Debug('UserRole.Name loop:' + u.userrole.name);
users.put(u.id, u);
}
for(task t:trigger.new) {
if (t.Status == 'Completed' && (t.Type == 'Face-to-Face Meeting' || t.Type == 'Follow Up') &&
t.RecordTypeId != callRecId){
//Select the contact associated with the new Meeting
//system.debug ('VALUE OF I = ' + i);
Contact c = contacts.get(t.whoid);
if(c==null) {
continue;
}
//Update fields in the contact from values in the Meeting Logged
c.Viability__c = t.Viability__c;
c.Estimated_T_12__c=t.Estimated_T_12__c;
c.Estimated_AUM__c=t.Estimated_AUM__c;
String roleName = '';
if ( users.containsKey(t.Ownerid) ) {
User u = users.get(t.Ownerid);
// System.Debug('User ' + u.Name);
roleName = u.UserRole.Name.toLowerCase();
// System.Debug('ROLE ' + roleName);
} else {
System.Debug('Owner Not Found');
}
if ( roleName.contains ('regional dir-ear')) {
System.Debug('Role Name = ' + roleName);
if (c.OwnerId != sysAdminId ) {
c.EAR_Assist__c = true;
c.EAR_Assist_Name__c = t.OwnerId;
c.EARAssistTask__c = t.id;
if ( c.LeadSource == 'Self-Sourced') {
c.EAR_Validate__c = true;
c.EAR_Validation_Date__c = t.ActivityDate;
}
} else if ( c.EAR_Assist_Name__c == t.Ownerid ) {
c.EAR_Validate__c = true;
if (c.EAR_Validation_Date__c == null || t.ActivityDate > c.EAR_Validation_Date__c) {
c.EAR_Validation_Date__c = t.ActivityDate;
}
}
}
contactstoupdate.put(c.id,c);
}
}
if ( contactsToUpdate.size() != 0) {
update contactstoupdate.values();
}
}
This occurs when the owner of a contact is changed on the contact page. The contact has several activities associated with it.
It is my understanding that when you change the owner of a contact that has activities associated with it, SF does and update/edit on this contact for each activity?
you can limit in this query or call this from aclass
create a global class method that return map that we can use in ur trigger .
this will help you ...
Could you give me some sample code of this?