QUESTION:
I want to move some attachments in Salesforce to a new parent object/record. What is the best way to export and import/reparent the attachments?
ANSWER:
Attachments cannot be "updated" to a new parent, but DemandTools MassEffect can be used to export the encoded attachments, re-import with the new parent record ID, and then delete the ones associated with the old parent record.
USING BULK API IS HIGHLY RECOMMENDED when importing encoded documents and attachments to ensure readable IDSave files. Starting in Version 2.5, MassEffect supports Bulk API. If running an earlier version of DemandTools, please upgrade to version 2.5 or higher and then follow the instructions notes below.
1. Use MassEffect to export the attachments to be re-parented (right click on the attachment table to export).
- Conditions can be to export attachments that meet specific criteria, i.e. Parent ID = 00XXXXXX
- To find attachments linked to specific type of object (i.e. Opportunities), specify a condition where the parent.type = Opportunity. The "type" field can be accessed from the "Parent" table/link by clicking the + to the left of the word "Parent" in the list of fields to base the condition on.
- Include all fields on the export file by selecting "Check All" in the Fields to Download section
- Use Microsoft Access (.accdb) as the output file type when saving the file to avoid the encoded "body" being truncated or corrupted
- Microsoft Access will use a "memo" field for this long area text field avoiding any truncation of data and any special characters will not impact the formatting of the output file.
2. Update the Parent ID field on this file to the ID of the new parent and use MassEffect to reimport.
- Include all fields on the export file by selecting "Check All" in the Fields to Download section
- Use Microsoft Access (.accdb) as the output file type when saving the file to avoid the encoded "body" being truncated or corrupted
- Microsoft Access will use a "memo" field for this long area text field avoiding any truncation of data and any special characters will not impact the formatting of the output file.
- Select "Insert" as the operation on the right
- Select "Use Bulk API" (version 2.5 and above)
- Auto-map all the fields back
- If using version 2.4 or lower or not using Bulk API may need to adjust the batch size:
- Depending on how many attachments are in the input file and how large they are the "Insert/Update/Delete Batch Size" setting in Options may need to be adjusted to something lower than 100 (the default batch size)
- Salesforce will throw errors if the amount of data being imported in one batch is over a certain size
- Changing the batch size will process smaller "chunks" of the input file avoiding having to break the actual file into smaller files
- A batch size of 50 is usually sufficient but if errors are returned by Salesforce simply adjust to a lower batch size and try again
- Depending on how many attachments are in the input file and how large they are the "Insert/Update/Delete Batch Size" setting in Options may need to be adjusted to something lower than 100 (the default batch size)
3. After confirming the attachments have all been re-parented correctly the original export file can be used to delete the old ones
- Select "Delete" as the operation on the right
- Map the ID from the input file to the ID field in the attachment table
More information on MassEffect can be found here.
NOTE: This solution is the same process that would be used to migrate attachments from one Salesforce org to another, exporting ALL attachments. Skip step 3 (to delete the existing attachments).