I am currently facing a problem where i am trying to update the owner of a record. I have a record ABC of type HistoryRecord. The owner of record ABC is 'John'.
Now, using apex, i have created a record called DEF of type HistoryRecord. Now, i want to assign the owner of DEF to be the owner of the record ABC (i.e. John).
How can i achieve this requirement? The code i tried is shown below:
HistoryRecord ABC= [Select Owner.Name from HistoryRecord where id = 123]; String ABCOwner= ABC.Owner.Name; HistoryRecord DEF = new HistoryRecord(); DEF.Owner.Name = ABCOwner;
When i execute the above code, i am receiving an error, "Field is not writeable: Name.Name"
How do i set the owner of record DEF to be the owner of record ABC?
The above process is called via a update trigger.