I need to upload some 2000 documents to specific users in salesforce. I have a csv file that has the Salesforce-assigned ContactID, as well as a direct path to the files on my desktop. Each contact's specific file url has been included in the csv. How can I upload them all at one and, especially, to the correct contact?
-
1What do you struggle with? Looks like you're on good path. Check https://help.salesforce.com/articleView?id=loader_attachments.htm&type=0, https://developer.salesforce.com/forums/?id=906F00000008ysmIAA. You want to load them as attachments? Chatter Files? Something else? – eyescream Feb 06 '18 at 07:42
-
@eyescream The difference between ParentID and OwnerID, I assume my ParentID should be the specific contact each file should be added to, is the OwnerID the ID of the salesforce user importing the files in? – Ethan Feb 06 '18 at 16:00
-
1Exactly. ParentId would be the parent record (Account, Contact, custom object...) against which you're loading. Owner can be set or left blank in which case it'll be "user used to load this data via data loader or any other means" Check field descriptions at https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_attachment.htm for example – eyescream Feb 06 '18 at 16:04
-
@eyescream Awesome! I am trying to upload things now but am getting errors no matter what I do. There are about 2000 documents that have to be uploaded and added as attachments to their respective contacts. I have enabled bulk api and made sure everything is mapped correctly. I've gotten 'Java Heap Space' errors as well as other things. Can we continue this conversation in chat? – Ethan Feb 06 '18 at 17:28
-
@eyescream also getting 'Maximum size of request reached. Maximum size of request is 52428800 bytes.' – Ethan Feb 06 '18 at 17:47
-
1Sorry man, no time today. Poke me tomorrow same time if it's still unsolved? You could try changing data loader's settings, set batch size = 1. It'll load 1 record at a time which will take a while but as the max file size is 25 MB anyway (https://help.salesforce.com/articleView?id=collab_files_size_limits.htm&type=5) it should help with memory limits. Not sure bulk api will help you much, try also with normal (SOAP) API. – eyescream Feb 06 '18 at 19:23
-
@eyescream Will do! I can get it to complete successfully with one record in the csv file, but the attachment never actually uploads. I says success, then I go and check the affected contact and see nothing under the files tab. Any idea why? – Ethan Feb 06 '18 at 21:09
-
"files" you say... Are you using Lightning Experience? The chatter-like files in LE should be uploaded as ContentNote, they kind of supersede Notes & Attachments from classic UI (you should still be able to view attachments as a related list I think). Chat tomorrow. For now switch to classic and check there and let's chat tomorrow – eyescream Feb 06 '18 at 21:27
-
@eyescream Sounds good, just as an update I have tired both Classic and LE. Every document that I am trying to upload is a .pdf that should appear in the "Files" tab within each contact. Chat tomorrow! – Ethan Feb 06 '18 at 21:51
-
Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/164678/discussion-between-eyescream-and-ethan). – eyescream Feb 07 '18 at 08:34
2 Answers
You indicated in the comments / chat that you want it as "Files".
The "Files" object is bit more complex than Attachments, you'll need to do it in 2-3 steps. What you see as a File (you might see it referred to in documentation as Chatter Files or Salesforce Content) is actually several tables. There's
ContentDocument
which can be kind of a file header (title, description, language, tags, linkage to many other areas in SF - because it can be standalone, it can be uploaded to certain SF Content Library, it can be linked to Accounts, Contacts, $_GOD knows what else)ContentVersion
which is well, actual payload. Only most recent version is displayed out of the box but if you really want you can go back in time- and more
The crap part is that you can't insert ContentDocument
directly (there's no create() call in the list of operations) .
Theory
So you'll need:
- Insert ContentVersion (v1 will automatically create for you parent ContentDocuments... it does sound bit ass-backwards but it works). After this is done you'll have a bunch of standalone documents loaded but not linked to any Contacts
- Learn the Ids of their parent ContentDocuments
- Insert
ContentDocumentLink
records that will connect Contacts and their PDFs
Practice
This is my C:\stacktest folder. It contains some SF cheat sheet PDFs.
Here's my file for part 1 of the load
Title PathOnClient VersionData
"Lightning Components CheatSheet" "C:\stacktest\SF_LightningComponents_cheatsheet_web.pdf" "C:\stacktest\SF_LightningComponents_cheatsheet_web.pdf"
"Process Automation CheatSheet" "C:\stacktest\SF_Process_Automation_cheatsheet_web.pdf" "C:\stacktest\SF_Process_Automation_cheatsheet_web.pdf"
"Admin CheatSheet" "C:\stacktest\SF_S1-Admin_cheatsheet_web.pdf" "C:\stacktest\SF_S1-Admin_cheatsheet_web.pdf"
"S1 CheatSheet" "C:\stacktest\SF_S1-Developer_cheatsheet_web.pdf" "C:\stacktest\SF_S1-Developer_cheatsheet_web.pdf"
Fire Data Loader, select Insert, select showing all Salesforce objects. Find ContentVersion. Load should be straightforward (if you're hitting memory issues set batch size to something low, even 1 record at a time if really needed).
You'll get back a "success file", it's useless. We don't need the Ids of generated content versions, we need their parents... Fire "Export" in Data Loader, pick all objects again, pick ContentDocument. Use query similar to this:
Select Id, Title, FileType, FileExtension
FROM ContentDocument
WHERE CreatedDate = TODAY AND CreatedBy.FirstName = 'Ethan'
You should see something like this:
"ID","TITLE","FILETYPE","FILEEXTENSION"
"0690g0000048G2MAAU","Lightning Components CheatSheet","PDF","pdf"
"0690g0000048G2NAAU","Process Automation CheatSheet","PDF","pdf"
"0690g0000048G2OAAU","Admin CheatSheet","PDF","pdf"
"0690g0000048G2PAAU","S1 CheatSheet","PDF","pdf"
Use Excel and magic of VLOOKUP or other things like that to link them back by title to Contacts. You wrote you already have a file with Contact Ids and titles so there's hope... Create a file like that:
ContentDocumentId LinkedEntityId ShareType Visibility
0690g0000048G2MAAU 0037000000TWREI V InternalUsers
0690g0000048G2NAAU 0030g000027rQ3z V InternalUsers
0690g0000048G2OAAU 0030g000027rQ3a V InternalUsers
0690g0000048G2PAAU 0030g000027rPz4 V InternalUsers
1st column is the file Id, then contact Id, then some black magic you can read about & change if needed in ContentDocumentLink
docs.
Load it as insert to (again, show all objects) ContentDocumentLink.
Woohoo! Beer time.

- 18,088
- 2
- 34
- 46
-
-
It worked! Visibility was a little wonky so I just deleted it and went off the default value which, from my understanding in the docs, is the same. Check chat – Ethan Feb 08 '18 at 12:20
Your CSV should contain following fields : - ParentID = Id of object you want to link the attachment to (the ID of the contact) - Name = name of the file - ContentType = extension(.xls or .pdf or ...) - OwnerId = if empty I believe it takes your user as owner - body = the location on your machine of the file (for instance: C:\SFDC\Files\test.pdf
Use this csv to insert the records (via data loader) into the Attachment object. You will then see for each contact, that records have been added to the 'Notes & Attachments' related list.

- 3
- 5