function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
vaibhav kamthanvaibhav kamthan 

how to create a contact related task through trigger

Sai PraveenSai Praveen (Salesforce Developers) 
Hi Vaibhav,

The code can be as below.
trigger AutoCreateTask on Contact (after  insert )  {
    system.debug('into contact trigger');
    list<task> tasklist = new list<task>();    
    for(contact con : trigger.new){
      Task tsk = new Task();
      tsk.whoId=con.id;
      tsk.Status = 'In Progress';
      tsk.Subject='call';
      tsk.Priority = 'High';
      tsk.ownerid= con.ownerid;
      tasklist.add(tsk);
        system.debug('task list'+tasklist);
    }
    if(!tasklist.isEmpty()){
       try{
           insert tasklist;
       
       }catch(DmlException de){
         System.debug(de);
       }
    }
}

If this solution helps, Please mark it as best answer.

Thanks,