Skip to main content
Hi all - I'm trying to figure out the appropriate way to have a trigger to update a lead's status to "SDR Meeting Booked" if an event activity is created by someone whose user profile ID = 00eE0000000adW0.

Modifying some code I found elsewhere I have the first part down (changing status based off an activity being created), but I'm not sure how to modify this to account for the second piece.

Total developer noob here, so any help is appreciated!

 

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 answers
  1. Feb 3, 2015, 8:15 PM
    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"