Importing Attachments Using the Sforce Data Loader
Aug 23, 2005Here is a great solution by Chris Bonacore
Some of
you have asked for details on importing attachments via the Data Loader so I
thought it may help for everyone.
If you
want to migrate from one org to another, then you first need to get a Weekly
Export Service download. Make sure you check the "Include
attachments" box. You will get an attachments.csv and the actual
attachments.
The key
to importing attachments is a little known feature inside Data Loader. The
part that is not documented is that the import wants the actual filename in the BODY field. So
for example, the attachments themselves have a ID name, let's say its 123456789
and it is on your hard drive in the C:\Export folder. So in the BODY field you
need to put C:\Export\123456789.
The only fields you need in the import file are - ParentId, Name, IsPrivate, OwnerId and Body.
This will work for any attachments by the way, not just org-to-org.
Now for a little trick with the Weekly Export Service...
I took the original attachments.csv, removed every column except ID, ParentId, Name, IsPrivate and OwnerId. I then created a new column called Body that was a formula field ="C:\WES\Attachments\"&B2. Where B2 was the ID column. So if the ID field was 12345, this new column was now C:\WES\Attachments\123435. I then copied this column down for every row and deleted the ID column.
The Attached File may help. And thanks to Lexi for helping me with this.

This works great, except that the data loader doesn't seem to be able to handle more than 200 attachments at a time. When I try to load more than 200 attachments, the data loader runs for a while, then aborts with no success or error logs. This might be an aggregate file size limitation, and not necessarily a number-of-attachments limitation.
Posted by: Drew Alexander | December 02, 2005 at 08:39 AM
Drew,
Try setting batch size to 1. Also make sure attachment name is less then 80 characters and size is less then 5 MB.
It worked for me using above settings.
Pramod
Posted by: Pramod Patil | December 06, 2005 at 10:46 AM
This is handy, but much more handy would be a reasonable way to mass delete. I've found no utility yet that presents attachments in a consolidated fashion where one could select a group of no longer useful attachments to delete and thus avoid the impending doom of crossing the meager storage limits that sf imposes. Any suggestions?
Tony
Posted by: Tony Primavera | January 25, 2006 at 10:16 AM
Hi,
I have a bunch of files that have not yet been imported into salesforce.com. I can determine from the path to the file - the name of the account that it is associated with..then I can run a query using the API to determine Account ID for the parentid...my question is that in the examples above, you dont include the full path to the file, are the files stored in a directory with the ID as the lowest level folder or is the file actually named with the ID without an extension.
Also, can you provide any examples of usage on the command line? I need to sweep a folder with hundreds of subfolders and look for files that need to be uploaded to Salesforce.com
Posted by: Kevin Kelly | June 21, 2006 at 09:38 PM
I wonder how this would work in an Org to Org migration scenario.
If I'm migrating say accounts and opportunities with attachments. Sequence would be to move accounts, opportunities and finally attachments. Since the parentId field in attachment.csv would be that of source org. We have to translate that to target Org Id.
I'd appreciate if some one could shed some light on how we accomplish that.
Posted by: Prakash | October 10, 2009 at 12:55 AM