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
Chidanand Magadum 24Chidanand Magadum 24 

Change the Owner of the record through Apex

Hi Guys,

Is it possible to change the owner of the record through Apex code? If so, how to achieve it?
Shailesh DeshpandeShailesh Deshpande

Yes, it is possible. You need to update the ownerId field with the Id of the User who should be the owner. For eg: In the below eg i am updating the Owner of the account.
 
Account a = new Account(id='0019000001GWXUB', ownerId = '0059000005GWMUB') // hard coding just as to make understand
update a;

 
Chidanand Magadum 24Chidanand Magadum 24
Thanks bro. Is it possible to set the value to the ROLLUP Summary field through Apex?
David Holland 6David Holland 6
Chidanand Magadum 24

It is not possible to set a rollup field - these are basically a formula field which looks at all child records which match the criteria set out in the field.

Many thanks