Any good Admin from time to time has to roll-up their sleeves and do some work with the Apex Data Loader (or LexiLoader if you’re using a Mac). It’s the "go to" data utility for mass uploading, updating and deleting records – but did you know you can also use it to mass upload attachments?
If you’re maintaining an existing org it might never come up, but when you’re merging Salesforce orgs or have a client that wants existing attachments moved into a new Salesforce instance it’s a cool trick!
If you are merging orgs, it’s probably best to do a Weekly Data Export to efficiently grab all the existing attachments. When doing so, make sure you select the option to include attachments. The Data Export will give you a starting file (Attachments.csv) that you can modify to create your import file as well as put all your existing attachments in one directory.
When you unzip the file provided by the Data Export you’ll see a directory similar to the following:
If you open the CSV file called "Attachements.csv," here is a quick breakdown of what you’re seeing:
- ID = the record ID of the Attachment you want to import
- IsDeleted = just a true / false to let you know if the attachment has been deleted
- Parent ID = is the record the Attachment is associated with / attached to in Salesforce (i.e. a Lead, Account, Contact, Opportunity, etc)
- AccountID = if the ParentID is not an Account record (e.g. an Opportunity record), this column will tell you if there was an Account associated to the Parent ID
- Name = this is what shows up as the "Title" in the Notes and Attachments related list in Salesforce
- IsPrivate = if the "Private" checkbox was checked (it’s going to be false – it’s really just for Notes as you can’t make an attachment private through the UI)
- ContentType = file format (e.g. .xls, .pdf, etc)
- BodyLength = just informational
- BodyLengthCompressed = just informational
- OwnerId – the Attachment Owner / User
The rest of the columns are the system stamps (Created Date / Time, Created By, Last Modified Date / Time, Last Modified By, etc)
Prepping Your Import File:
To get the file ready for import you can collapse your .csv file down to just following columns:
Body – this where you tell the Data Loader where to get the actual file that will be imported. It should be the directory on your computer down to the file name.
If starting from a Data Export, the directory path will end with the Salesforce ID for the file that was listed in the "ID" column in the Attachments.csv. Let’s look at how I constructed this example:
I started with the directory on my computer that held my Data Export, "/Users/shell/Desktop/WeeklyExport Backup/WE_00DA0000000IXfvMAG_1/Attachments/" and then I appended the file ID "00PA0000000gBURMA2″ that was in the "ID" column of my Attachments.csv from my Data Export.
Alternatively, if you are importing a new file into Salesforce, the syntax might look like:
C:documents and settingsshelldesktopattachmentsfile.xls
Content Type – if using the file the Data Export, use the same information that was in the Attachments.csv file, otherwise list the file extension (e.g. .xls, .pdf, etc)
Name – as stated previously, this will be the "Title" of the Attachment
OwnerID – the Salesforce record ID for the User that will be associated with the attachment
ParentID – the Salesforce record ID that you would like the attachment associated with (e.g. the Lead, Account, Contact, Opportunity, etc).
When done, your import csv file should look something like this:
Performing the Import:
I won’t get into how to use the Data Loader, but here are some things to know for this procedure. In "Step 2″ of the Data Loader, make sure you tell Salesforce to Show All Objects to expose the "Attachments" object
Your field mappings will look something like this:
There is one knowledge article hiding out in Salesforce help that is a good primer – search for "How do I import attachments using my Data Export files?"
Other blog post tutorials on how to use the Data Loader: