
trigger changeLeadStatus on Event (before insert, before update) {
String desiredNewLeadStatus = 'SDR Meeting Booked';
List<Id> leadIds=new List<Id>();
for(Event t:trigger.new){
if(String.valueOf(t.whoId).startsWith('00Q')==TRUE){//check if the task is associated with a lead
leadIds.add(t.whoId);
}
}//for
List<Lead> leadsToUpdate=[SELECT Id, Status FROM Lead WHERE Id IN :leadIds AND IsConverted=FALSE];
For (Lead l:leadsToUpdate){
l.Status=desiredNewLeadStatus;
}//for
try{
update leadsToUpdate;
}catch(DMLException e){
system.debug('Leads were not all properly updated. Error: '+e);
}
}//trigger
4 Antworten

Hi Mithun, I'm getting the following error when I try to use the code on an Apex Trigger:"Error: Compile Error: Incorrect SObject type: Event should be Lead at line 1 column 1"