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
Rohit SharmaGRohit SharmaG 

Task creation for other User via trigger

Hi All,

I want to assign task to user, Not to lead/contact .  Case Comment and Case has master details relationship.

trigger TaskForCaseCommentTrigger on Case_Comment__c (after insert)
  List<Task> newTasks = new List<Task>();

  //Loop through all records in the collection
  //for(Case_Comment__c cc:
   for(integer i=0; i<; i++)
    //List<Case> cases = [select id,Owner.Id from Contact where accountId = :a.Id];
       system.debug('Owner ID----'[i].Case__r.OwnerId);
       newTasks.add(new Task(
            ActivityDate =,
            WhoID =[i].Case__r.OwnerId,
            Status = 'Not Started',
            type = 'Other',
            Priority = 'Normal',
            Subject = 'Case Comment Added',
            description =[i].Comment__c
   insert newTasks ;

Virendra ChouhanVirendra Chouhan
Hi Rohit,

I think you have to use Owner field of Task object.
and assign the user's id on that.