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
Ram ChaturvediRam Chaturvedi 

How can i change ownership of any custom object record , by using apex code ?

I want to change ownership of any record to the another user so if i am trying to change "owner.id" it gives error not writable .
KaranrajKaranraj
Ram - The API name of the Owner field is "OwnerID". Can try instead of using Owner.Id?
Darshan FarswanDarshan Farswan
Hi Raj

As Karanraj said, you will have to update the OwnerID field and not Owner.Id.

Owner.Id will select the Owner user and try to update its Salesforce ID, which is always Read-Only.