How can we change parentid of note and attachment using apex. I wonder if we could even do that. Any help would be appreciated.

2 Answers 2


The parent ID is not writeable after insert. You will have to copy the attachment / note to a new attachment/note, then set the parent id there. Insert the new one, and delete the old one.

For example:

Attachment a = [SELECT Name, Body FROM Attachment WHERE ParentID = :oldParentId];
Attachment b = New Attachment(Name = a.Name, Body = a.Body);
b.parentID = newParentId;
insert b;
delete a;

Nope, you cannot directly update the ParentId field on the note and attachments. You can find more information on the below link what all you can update or insert.


There is a workaround to change the parentId, it involves the below step:

  • Create new records of the notes and attachment with the new parentId and copy over all the fields from the old records.
  • Delete the old records

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .