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
Siddharth LakhotiaSiddharth Lakhotia 

Field is not writeable: Task.Owner


I am getting following error  while writting Test class

User-added image
Deepak Pandey 13Deepak Pandey 13
Hi Sidharth,
     Firstly you just insert user with a profile and use runasuser.

 Profile p = [SELECT Id FROM Profile WHERE Name='ProfileName']; 
        User u = new User(Alias = 'standt', Email='', 
            EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US', 
            LocaleSidKey='en_US', ProfileId = p.Id, 
            TimeZoneSidKey='America/Los_Angeles', UserName='');

                Task t = new Task();
                t.OwnerId =;
                t.Status='Not Started';
                insert t; 

try this in your method.