Could someone help me with this basic trigger? When a new task is inserted, I want to update the Status field in the lead to match the CallResult field in the Task. Here is my broken code:
trigger callResult on Task (after insert)
{
for (Task task : Trigger.new)
{
if (task.Who != null)
{
String leadName = task.Who.Id;
String callResult = task.CallDisposition;
List<Lead> relatedLead = [SELECT Id, Status FROM Lead WHERE Name = :leadName LIMIT 1];
if (relatedLead.size() > 0)
{
relatedLead[0].Status = callResult;
}
}
}
Task.WhoId
, which is more clear thanTask.Who.Id
and is the actual field, not a reference object.Task
.