8

I need to load files into Salesforce via an API as part of some integration work. I want to be loading files as Salesforce Files (not attachments) so we can version files if need be and I also need to make sure that the resulting uploaded file is available to Community licensed users who have access to the record. There seem to be two API options:

  1. Using the Chatter API where you upload a file to Files home for a user through a request to /connect/files/users/userid (example on this page) and then relate it to a record by doing a request to /chatter/feed-elements as described here.
  2. Uploading as a ContentDocument via the REST API, although the example shown in API describe that in the context of Salesforce Content, which is not something we are interested in using.

Is the best option one of the above or something else altogether? Are there any limits that I should be aware of? I think that either option would be fine for files 50MB or potentially a bit more, which would be enough for us. In terms upload numbers, we're probably going to be around a few thousand at most per day.

1
  • Salesforce Content is older name for Salesforce Files
    – cropredy
    Feb 1 at 20:05
2

If you're using Files, you are using Salesforce Content. In fact, when you add a Chatter File, the platform is generating a ContentDocument/ContentVersion/ContentDocumentLink just as if you were using those objects directly - in addition to the Chatter post(s).

The model sounds complicated, but it can be relatively simple to use the REST API to insert a File.

When you insert a ContentVersion record with a null ContentDocumentId field, it will create the ContentDocument for you.

If you populate the FirstPublishLocationId field with the Id of the record you want to relate the File to when you insert the ContentVersion, the platform will also create the ContentDocumentLink record for you. One call to insert and relate a File!

https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_contentversion.htm

If the file is larger than 37.5 MB, you'll need to send the file data in a multi-part message. In this manner, you can upload a file up to the 2GB max for Files.

Some more detail on this can be found here:

https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_sobject_insert_update_blob.htm

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.