I need to move Attachments from one SF to another SF, but the final parent object is not in the destination org. So I've created temporary records and plan to update the ParentId of the attachments later.

But when I was ready to update the ParentId of the Attachments, it didn't show a map to the "parentID". I read somewhere that when we insert Attachments its parentID becomes read-only after insertion. I loaded around 6GB of data to my temporary records. How can I modify the ParentIds of all those Attachments?

  • I know this is an old post, but is the only way to move an attachment to copy it by inserting and delete from other record? The comment on here about upsert to external id, is that to move it or is that still copy and delete?
    – john
    Commented May 11, 2017 at 16:40
  • Hi @john, The upsert is for Copy and Delete only process. It is just for referencing the parent records. Commented May 29, 2017 at 9:34

2 Answers 2


You can clone the entire attachment and then delete the old one.

this code works for me :

List<Attachment> attachmentsToInsert = new List<Attachment>();

List<Attachment> attachmentsToDelete = new List<Attachment>();

Attachment tempAtt;

for(Attachment attachment: [
        SELECT SystemModstamp, ParentId, OwnerId, Name, 
            LastModifiedDate, LastModifiedById, IsPrivate, IsDeleted, 
            Id, Description, CreatedDate, CreatedById, 
            ContentType, BodyLength, Body 
        FROM Attachment 
        WHERE parentId=:'parentid']) {

    tempAtt.parentId = quoteSelWrap1.quot.Id;



insert attachmentsToInsert;
delete attachmentsToDelete;
  • 2
    welcome to salesforce.stackoverflow ! Can you try to format all the code you posted ? edit and use the {} button in the editor. Commented Jan 10, 2014 at 12:33

ParentId is not updatable on Attachment, as you've discovered. This means you will not be able to modify the existing attachments to reparent them to a new parent.

You will probably need to use an external ID on the parent records when you load the attachments in the first place.

This involved setting either a text, number, or email field to both ExternalId and Unique.

Let's say you do this with Account and you add the External Id field called Import_Key__c. Once you've added that field you will need to populate it with a unique value. This can be anything, even a duplicate of the record Id.

Then your mapping will look something like this:

SourceField          Salesforce Field
ParentId             Parent.Import_Key__c

You need to then use the Upsert operation. When upserting the attachment, salesforce will use the external Id field value to map back to the proper parent record Id and populate ParentId with the correct value.

Yes, you will need to reload all 6GB of those attachments, but I'm afraid it is the only way.

  • Actually there are field in my Objects i.e. Account, Contact, Opportunity etc that can used as externalID. Can I able to map them now in the UPSERT operation of Attachment with those records ExternalID(uniques) ? Commented Sep 2, 2013 at 9:26
  • Is there not any way, through which I raise a case in Premium Support and they will enable the 'parentID' field in editable mode during Update Operation for Attachments ? @Peter Commented Sep 2, 2013 at 9:29
  • They might work. Give them a try. I would also contact support. I'm not aware that this is something they can provision for temporarily or help you perform, but you can only find out if you ask.
    – pchittum
    Commented Sep 2, 2013 at 23:15
  • 1
    Honestly, in most cases, it would be faster to simply delete the records and re-insert them. I've had to do this before, and it's not as painful as it sounds, unless you have dialup or DSL.
    – sfdcfox
    Commented Sep 3, 2013 at 5:08
  • yeah, I am doing the same presently. Commented Sep 4, 2013 at 7:29

You must log in to answer this question.

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