Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
up vote 5 down vote accepted

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;
share|improve this answer

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
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.