You need to sign in to do that
Don't have an account?
MrWasabi
Make Trigger Fire Only on Leads
I have a task Trigger that validates and works great on Leads. The problem is that the trigger fires on also for tasks on Accounts and Opporutnities. I've very new to Apex, so I'm sure I am overlooking something simple.
How do I make this trigger fire only when inserting a task on a lead?
trigger UpdateLeadStatusOnTask on Task (after insert) { //Retrieve task data after a new task has been saved Task theTask = trigger.new[0]; //Create the lead (Lead Status and the IsConverted fields) for the Lead which the task was logged against Lead theLead= [Select Status,IsConverted from Lead where id=:theTask.WhoId]; //Check to see if Marketo is the owner of the task, we only want tasks not owned by Marketo if(theTask.ownerid<>'00540000001GDw2'){ //Only use leads that have a status of open if(theLead.Status == 'Open'){ //Change the status to contacted theLead.Status = 'Contacted'; //apply the changes to the lead update theLead; } } }
Hi,
You need to check that whoId starts with ('00Q').
Please see the changes in the code:
All Answers
Hi,
You need to check that whoId starts with ('00Q').
Please see the changes in the code:
Ramit, this is excellent! Thank you!