You need to sign in to do that
Don't have an account?
Marcus Stoll
Trigger to update lead status based off event created by specific user profile
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!
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
You have to use after context (after insert and after update) and update your trigger like below.
For now, i'm querying profile id of "System Administrator", you can replace it with your required profile.
Let me know if you face any issues.
Best Regards,
Mithun.
"Error: Compile Error: Incorrect SObject type: Event should be Lead at line 1 column 1"
I think you created trigger on Lead, you shoud create trigger on Event object not on Lead.
Customize > Activities > Event Triggers > NEW
Best Regards,
Mithun.