+ Start a Discussion
SayasoniSayasoni 

Writing to the Task's Assigned to Field

I have a trigger that inserts a new task to a custom object and one of the fields is the Assigned To field,  Is there a way that i can alter that field or is it READ ONLY.

Thanks..

Navatar_DbSupNavatar_DbSup

Hi,

 

Yes you can alter the Assigned To ID field in task.  Assigned To ID is a label and the OwnerId is the api name.

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

SayasoniSayasoni

I have tried to write to the Task's Assigned To Field label whose API name is Owner, but it seems it's readonly. I want the assigned to field label to reflect a salesforce user that the task belongs to. Here is my code snippet 

                          ...
  String username = 'saya@pros.com';
               
              List<User> userList=[Select Id,Name,Email 
        	                                FROM User
        	                                WHERE Email=:username
        	                                Limit 1];
                   
        
                       Task taskToAdd = new Task(Description = myPlainText,
                                 Priority = 'Normal',
                                 Status = 'Inbound Email',
                                 Subject = email.subject,
                                 IsReminderSet = true,
                                 ReminderDateTime = System.now()+1,
                                 Owner=userList.get(0).Name);
                             ...
                              

 Am I the one doing it wrong or there is a different field to be used in the Task object to reflect the saleforce user fullname that the task belongs to.

Thanks

 

Saya.