1

I'm trying to send an array of content versions via the Standard API that Salesforce suggests :

Using POST method to :

https://SandboxName.my.salesforce.com/services/data/v43.0/sobjects/ContentVersion

[
 {
  "VersionData":"/9j/4AAQSkZJRgABAQEAYABADn/2Q==",
  "PathOnClient":"Array1.jpg",
  "Description":"Array1",
  "Document_Type__c":"1"

 },

 {
  "VersionData":"/9j/4AAQSkZJRgh25==",
  "PathOnClient":"Array2.jpg",
  "Description":"ARRAy2",
  "Document_Type__c":"1"
 }
]

With one file - Its working, but when I change it to array and add another file - Its throw me this error :

**[
    {
        "message": "Json Deserialization failed on token 'null' and has left off in the middle of parsing a row. Will go to end of row to begin parsing the next row",
        "errorCode": "INVALID_FIELD"
    }
]**

My questions are:

  1. What the problem here???

  2. I'm sending the request ok? and if I do - this is legal to do? (send it as an array).

  3. There are limitations that I need to be aware of using an array?

Thank you.

2

The way you are following can insert only one record. In order to create record in bulk using REST API, you need to use Composite Tree resource- Tree resource can be used to create nested records, you can also create multiple, unrelated records of the same type.

So endpoint would be: https://SandboxName.my.salesforce.com/services/data/v43.0/composite/tree/ContentVersion

Request Body:

{"records" :[
 {
  "attributes" : {"type" : "ContentVersion", "referenceId" : "ref1"},
  "VersionData":"/9j/4AAQSkZJRgABAQEAYABADn/2Q==",
  "PathOnClient":"Array1.jpg",
  "Description":"Array1"
 },

 {
  "attributes" : {"type" : "ContentVersion", "referenceId" : "ref2"},
  "VersionData":"/9j/4AAQSkZJRgh25==",
  "PathOnClient":"Array2.jpg",
  "Description":"ARRAy2"
 }
]
}

P.S: In each row you would need to pass a reference id for each record as shown above.

SOURCE ARTICLE: https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_composite_sobject_tree_flat.htm

  • 1
    The Composite resource would also work in this situation. – sfdcfox Dec 17 '18 at 10:59
  • @Ayub Is there any Limitation (I guess there are) on the size of the sum of all the contentVersions that I created? What is the Max size that I can handle with? Thnkas – Salvation Dec 17 '18 at 12:11
  • You cannot exceed the payload limit...I'm not sure how much it is 3mb or 6mb but it's fact there is limit and you need to take care of that....especially while uploading files via api... – Ayub Dec 17 '18 at 12:21
  • @Ayub In SF docs - They wrote that I can upload a file up to 2 GB (including headers) when uploaded via REST API - help.salesforce.com/… What am I missing here?? Many Thanks for you help – Salvation Dec 17 '18 at 14:45
  • It's when you are using salesforce user interface....if you are using api then regardless what you are uploading, api limits will be counted against... – Ayub Dec 17 '18 at 15:55

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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