• MrWasabi
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies

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;
        }
    } 
}

 

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;
        }
    } 
}