function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
asadimasadim 

Moving Attachment across parents

Hi,

 

We have thousands of attachments that we want to associate to new parents. Exporting them using Data Loader and loading them into Access/Excel will cause bad data imports (data is delimited incorrectly or the Office tool won't be able to open them). In Apex you can't overwrite the parentId field.

 

What's the solution? Any ideas? Thanks!

Best Answer chosen by Admin (Salesforce Developers) 
_Prasu__Prasu_

In Apex you can do cloning the Attachment record and then delete the original record. Its not possible to update ParentId field. bulk cloning will not be possible as Salesforce has Governor limit on the heap size. Best option will be using the Salesforce API with .NET or JAVA and writing a custom logic. 

All Answers

_Prasu__Prasu_

In Apex you can do cloning the Attachment record and then delete the original record. Its not possible to update ParentId field. bulk cloning will not be possible as Salesforce has Governor limit on the heap size. Best option will be using the Salesforce API with .NET or JAVA and writing a custom logic. 

This was selected as the best answer
asadimasadim

Thanks. Why would the heap size limit cause an issue? Can't I write a Batchable class that processes the attachments? Maybe I'm not clear on the heap size limit (it's 6MB for batches).

_Prasu__Prasu_

Heap size will exceed in the case of cloning the attachments of more than 4MB in that case. After you make a clone, heap will be containing two records of 4MB files. I never tried this in batch Apex, but in the trigger it does create a heap size limit reached exception. 

 

Batch size of 1 should solve the heap size problem.

asadimasadim

Thanks.