Import and Export Attachments in Salesforce : jayakrishnasfdc

Import and Export Attachments in Salesforce
by: jayakrishnasfdc
blow post content copied from  Jayakrishna Ganjikunta
click here to view original post

Attachment Represents a file that a User has uploaded and attached to a parent object.

Field Name Field Label Type Digits Length Precision Scale
Body Body base64
BodyLength Body Length int 8
ContentType Content Type string 120
CreatedById Created By ID reference 18
CreatedDate Created Date datetime
Description Description textarea 500
Id Attachment ID id 18
IsDeleted Deleted boolean
IsPrivate Private boolean
LastModifiedById Last Modified By ID reference 18
LastModifiedDate Last Modified Date datetime
Name File Name string 255
OwnerId Owner ID reference 18
ParentId Parent ID reference 18
SystemModstamp System Modstamp datetime

To Move the attachment data from one salesforce org to another org or from one object to another or do import form a storage location we need to follow 2 basic rules of Export and Import.

Export Attachments

1. Login to with your login to Salesforce.

Note : We can Use any Data loading tool like Data loader, and Talend etc. which supports to download attachments.
2. Suppose if you are using  then Click on  “New Task” and select “Export” button.
3. Select Attachment object, click Next.

4. Select the List of fields and if any filter want to apply and Query/Click on Next.
     or Use below SOQL Query for example querying account objects attachments , You can use any Object to download from that specific or All objects.

SELECT Id, Name, Body, BodyLength, ContentType, CreatedById,
CreatedDate, IsDeleted, Description, LastModifiedById, LastModifiedDate,
OwnerId, ParentId, IsPrivate, SystemModstamp
FROM Attachment
WHERE ParentId IN ( SELECT Id FROM Account )

5. Click “Save & Run”
6. Wait the process

6. Once the task is completed, download the attachments by clicking on the task manager on the link next to the export task. This will download all of the attachments compressed into a .zip file, example: Attachment

7. If you select other fields on top of Body field, you will find a CSV file with the same name, example: Attachment Export-02_13_2014-13_43_08.csv, all fields selected when you in  export in will be available in this CSV file.

Import Attachments

  1. Create an attachments.csv file (the name of the file is unimportant) with the following column headers:

·ParentId – ID of the record to which the attachment should be associated
·Name – Name of the attachment
·ContentType – Format of the extension (e.g. .xls, .pdf, etc)
·OwnerID – ID for the owner of the attachment
·Body – File path to the Attachment on the local machine (C:\documents and settings\schun\desktop\attachments\file.xls)

2 ·Log in to the Data Loader.

3 ·Select the “Insert” command.

4·In the ‘Select Sforce Object’ step, select the ‘Show all Sforce Objects’ checkbox and then select “Attachments”.

5. Choose the attachments.csv file.

6. In the mapping step, map the following fields:

*Parent ID
*Owner ID
*Body – Make sure to map the Body column which you created previously with the file extension. This is how you designate the file and location of the attachments to be inserted.

7. Click “OK” to proceed with the insert. It may take a few minutes but the attachments should be successfully uploaded to your salesforce org.

8. Also make sure you are using valid Parent Id / Owner Id, as ParentId would be different in second org. So those attachments would get attached to correct Record.

July 15, 2021 at 09:29PM
Click here for more details...

The original post is available in Jayakrishna Ganjikunta by jayakrishnasfdc
this post has been published as it is through automation. Automation script brings all the top bloggers post under a single umbrella.
The purpose of this blog, Follow the top Salesforce bloggers and collect all blogs in a single place through automation.