Newer Version Available

This content describes an older version of this product. View Latest

Get Records With a Request Body Using sObject Collections

Use a POST request with sObject Collections to get one or more records of the same object type. A list of sObjects that represents the individual records of the specified type is returned. The number of sObjects returned matches the number of IDs passed in the request.

The request retrieves up to 2,000 records of the same object type

  • If you specify an invalid field name or a field name that you don’t have permission to read, HTTP 400 Bad Request is returned.
  • If you don’t have access to an object, or if a passed ID is invalid, the array returns null for that object.

The sObject Blob Retrieve resource isn’t compatible with Composite API requests, because it returns binary data instead of data in JSON or XML formats. Instead, make individual sObject Blob Retrieve requests to retrieve blob data.

Note

Syntax

URI
/services/data/vXX.X/composite/sobjects/sObject
Formats
JSON, XML
HTTP Method
POST
Authentication
Authorization: Bearer token
Request Body
1{
2   "ids" : ["recordIds"],
3   "fields" : ["fieldName"]
4}
Parameters
Parameter Description
recordIds Required. A list of one or more IDs of the objects to return. All IDs must belong to the same object type.
fieldNames Required. A list of fields to include in the response. The field names you specify must be valid, and you must have read-level permissions to each field.

Example

Example Request
1curl -X POST https://MyDomainName.my.salesforce.com/services/data/v60.0/composite/sobjects/Account -H "Authorization: Bearer token" -H "Content-Type: application/json" -d "@exampleRequestBody.json"
Example Request Body
1{
2   "ids" : ["001xx000003DGb1AAG", "001xx000003DGb0AAG", "001xx000003DGb9AAG"],
3   "fields" : ["id", "name"]
4}
Example Response Body
1[
2   {
3      "attributes" : {
4         "type" : "Account",
5         "url" : "/services/data/v60.0/sobjects/Account/001xx000003DGb1AAG"
6      },
7      "Id" : "001xx000003DGb1AAG",
8      "Name" : "Acme"
9   },
10   {
11      "attributes" : {
12         "type" : "Account",
13         "url" : "/services/data/v60.0/sobjects/Account/001xx000003DGb0AAG"
14      },
15      "Id" : "001xx000003DGb0AAG",
16      "Name" : "Global Media"
17   },
18   null
19]