4

There is a maximum batch size for the number of records returned by an API call.

Most of the documentation for the API calls reference including a .json file, and some, like the Update a Record page, refers to including multiple records - Records in a single file must be of the same object type.

However, I can't seem to find a limit on how many records I can pass to Salesforce in a single API call.

What is the limit on the number of records I can pass?

  • Are you referring to an endpoint to create / update records, (such as PATCH /vXX.X/sobjects/Account/id or POST /vXX.X/sobjects/Account), or a custom Apex REST endpoint? – Dan Watt Aug 14 '14 at 20:32
  • @DanWatt An endpoint, such as the one I point to here, the PATCH /vXX.X/sobjects/Account/id. – Luke Shaheen Aug 14 '14 at 20:35
  • @DanWatt Although, actually that answers my question, doesn't it? /id points to a single ID, so I can't even update multiple rows (ids). – Luke Shaheen Aug 14 '14 at 20:36
5

If you are using the standard endpoints, such as POST /vXX.X/sobjects/Account or PATCH /vXX.X/sobjects/Account/id, then yes, you can only create or update one at a time.

The bulk API, or even the SOAP API, can be used to upload multiple objects at the same time.

You can also create your own APEX REST endpoint. As an example:

@RestResource(urlMapping='/test/*')
global with sharing class TestRestController{
   global class RequestBody {
       global List<Account> accounts;
   }

    @HttpPost   
    global static List<Account> createBulk(TestRestController.RequestBody req) {
        insert req.accounts; 
        return req.accounts;
    }

}

You can then post to that endpoint the following data, and get back full data about the created Account objects.

POST https://[instance].salesforce.com/services/apexrest/test/
{
  "req" : {
    "accounts": [{"name": "test1"},{"name" : "test2"}]
  }
}

Using a custom endpoint would be subject to the normal governor limits including a maximum request and response size of 3MB.

  • Thanks Dan for pointing out the custom APEX REST endpoints. I had no idea those were available, looks like they will be very useful throughout my integration. Is there a resource or a quick list of downsides to creating custom endpoints? Smaller API limits, not efficient, etc? Anything like that? – Luke Shaheen Aug 15 '14 at 17:51
  • @John The limits are basically the same as any Apex Code (same governor limits, etc). As such, they can be incredibly powerful. For example, we wrote a custom rest service that can be called by our internal systems to update many records from Siebel at once using an External ID field. – sfdcfox Aug 15 '14 at 18:55
4

Using "patch", the limit is 1. That's because this API is really intended for mobile devices, of which you'll usually be working with one record at a time. Also, it's considered the RESTful design, embedding the id into the URI, and using HTTP verbs to manipulate data.

There are alternatives, though. You could use the REST Bulk API to make a batch you can upload in pieces. You could write your own custom REST API functions to handle multiple records.

And, of course, you could fallback to SOAP for those times when you want synchronous multiple updates, as session tokens are interchangeable.

  • Good to know the session tokens are interchangeable. I'm trying to avoid having to regress to SOAP, so the Bulk API + possible custom endpoints should do the job. – Luke Shaheen Aug 15 '14 at 17:53

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.