Skip to main content
3 of 5
added 247 characters in body
sfdcJameson
  • 1.1k
  • 12
  • 23

Revised Answer:

Heres what I would do if I were you

Trigger

trigger TestTaskTrigger on Task (after insert) {
       if(trigger.isInsert && trigger.isAfter){
            Task_Methods.setWhat(trigger.new);
        }
}

Class

public class Task_Methods{
    public static void setWhat(List<Task> newList){
        List<Task> tList = new List<Task>();
        for(Task t : [SELECT Id, Who.AccountId FROM Task WHERE Id IN :newList AND WhoId != null AND Who.type = 'Contact']){
            t.WhatId = t.who.AccountId;
            tList.add(t);
        }
        if(tList.size() > 0){
            update tList;
        }
    }
}
sfdcJameson
  • 1.1k
  • 12
  • 23