2

I have requirement to upload files to SFDC attachments object. I am making REST call from my Java code to SFDC with required details.

curl -X POST \
  https://ap.salesforce.com/services/data/v29.0/sobjects/Attachment/ \
  -H 'authorization: Bearer sessionId' \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -d '{
    "ParentId":"00T0K0000243CvXXX",
    "Name":"Test123.txt",
    "body":"base64Coded"
}'

But above REST call support only single Attachment at a time. Is there any way I can upload multiple files in a single shot. Or can we leverage SFDC Bulk API anyhow?

3
  • What is the MAX file size I can upload using REST API calls. I tried and Salesforce threw exception on 25MB but I did not find any doc which confirm on the size limit. Can someone point me to the relevant doc link.
    – San
    Commented Jul 4, 2018 at 7:03
  • size limit (from this developer.salesforce.com/docs/atlas.en-us.api_rest.meta/…) is You can insert or update blob data using a non-multipart message, but you are limited to 50 MB of text data or 37.5 MB of base64–encoded data.
    – davejagoda
    Commented Mar 22, 2019 at 0:35
  • @davejagoda this to create document i guess and not for the attachment
    – Hunt
    Commented Jun 11, 2020 at 8:58

1 Answer 1

3

You can use Bulk API here to upload attachment in bulk.

  • First, you need to Create a request.txt File which will include details of files.
  • Then Create a Zip Batch File with Binary Attachments

  • Then Create a Job for Batches with Binary Attachments

  • Finally, Create a Batch with Binary Attachments.

You can follow the details steps from here: Load Binary Attachments

10
  • Thanks Tushar. As far I understood, this will create a batch job in Saleaforce and will execute as soon as it get CPU. I can use batch Job id returned in the response for checking the completion status but once the job is completed how to check what are the attachments which got failed and what was the cause of failure.
    – San
    Commented Jun 26, 2018 at 14:10
  • @San You can use Get Batch Results to check the status. Commented Jun 27, 2018 at 4:53
  • As per the link, in request.txt file each row will represent one record, in my case it will be attachment file details including the content of file being uploaded under body column. Do we have size limit on request.txt because I could see SF doc says Batches size should not be more than 10MB? In my case individual file can go up to 25MB.
    – San
    Commented Jun 27, 2018 at 6:45
  • @San you need to give path here of your file. Commented Jun 27, 2018 at 6:52
  • Ohh, I did not understand. if I give path rather than content will SF take care of downloading from the source location and upload to SF Attachment. (we have our files stored at Amazon S3)
    – San
    Commented Jun 27, 2018 at 6:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .