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.

1 Answer 1


You can not set the Owner name directly what you can do assign the Id

HistoryRecord ABC= [Select OwnerId, Owner.Name from HistoryRecord where id = 123];
HistoryRecord DEF = new HistoryRecord();
        DEF.OwnerId = ABC.OwnerId;
  • Will setting the ownerId automatically sets name as well.
    – user51525
    Feb 16, 2018 at 8:20
  • @karna yes it does
    – d_k
    Feb 16, 2018 at 8:22

You must log in to answer this question.