I wrote a trigger to update a field (boolean value) in LEAD when a TASK is added to the lead. Trigger works fine in DEV box but when I deploy it, its giving me Exception error clashing with one other trigger in production. I have added both the codes here. Please help me resolve this.
The trigger is below -
trigger triggerOnLead on Task ( after insert, after update) {
List<Id> leadIds=new List<Id>();
for(Task t : Trigger.new){ {
leadIds.add(t.whoid);
//system.debug('test' +leadIds);
}
List<Lead> leadList = [Select id, status, isActivity__c from Lead where id =:leadIds and status='Open - Not Contacted' and isActivity__c=false ];
for(Lead l:leadList ){
l.isActivity__c = true;
}
try{
update leadList;
} catch(DMLException e){
system.debug('Lead Activity is not updated properly!. Error: '+e);
}
}
And I'm getting the below ERROR when deploying: System.LimitException: Too many SOQL queries: 101 Stack Trace: Trigger.sampleTrigger: line 10, column 1
As it's clashing with trigger -
trigger sampleTrigger on Event(after insert) {
string sWhtId = trigger.new[0].WhatId;
string sWhoId = trigger.new[0].WhoId;
Event objT = [Select id,WhatId,WhoId from Event where id =: trigger.new[0].id ];
if(sWhtId != '') {
List<Account>lstAcc = [Select id,LastModifiedById,ownerid from Account where id =: sWhtId ];
if(lstAcc != null && lstAcc.size()>0){
if (trigger.new[0].LastModifiedById != null) {
if(lstAcc[0].ownerid != trigger.new[0].LastModifiedById) {
trigger.new[0].IsOwnerSame__c = true;
}
}
else {
if(lstAcc[0].ownerid != trigger.new[0].CreatedById) {
objT.IsOwnerSame__c = true;
}
}
}
}
if(sWhoId != ''){
//For Contact
List<Contact>lstCon = [Select id,LastModifiedById,ownerid from Contact where id =: sWhoId ];
if(lstCon != null && lstCon.size()>0) {
if (trigger.new[0].LastModifiedById != null) {
if(lstCon[0].ownerid != trigger.new[0].LastModifiedById) {
trigger.new[0].IsOwnerSame__c = true;
}
}
else {
if(lstCon[0].ownerid != trigger.new[0].CreatedById) {
objT.IsOwnerSame__c = true;
}
}
}
}
}