+ Start a Discussion
arjunkodidalasfdc1.3904276015566733E12arjunkodidalasfdc1.3904276015566733E12 

Attaching a task to Lead

Hi,

I  need to assign a Lead to Task. How can i do that. 



I know that we can create a task with who id of lead as below.
Task newTask = new Task(
               ActivityDate = Date.today(),
               WhoID = Lead.OwnerId
               OwnerId = User.UserId;
               Status = 'Not Started',
               type = 'Other',
               Priority = 'Normal',
               Subject = 'Other',
               description = taskDescription
     );
insert newTask;

But i have a situation to assign a Task to Lead. How can i assgn it? Is there any method to assign a task to lead?

Lead newLead=new Lead();
newLead.TaskID= newTask.TaskID;  
             (or)
newLead.Activities.Add(newTask.TaskID)    like this?

Thanks.




  
Elie.RodrigueElie.Rodrigue
You need to set the whoId of the task as the LeadId

Task newTask = new Task(
               ActivityDate = Date.today(),
               WhoID = Lead.Id,
               OwnerId = User.UserId;
               Status = 'Not Started',
               type = 'Other',
               Priority = 'Normal',
               Subject = 'Other',
               description = taskDescription
     );


WhoId needs to be a lead or contact id
WhatId can be account, campaign, case or custom object with activity enabled.