---
schema_version: "1"
id: 0f34d08feae70d54ef3d84ccc08caa4b7ff067549ceebb8498111258388b07d9
title: Create Records Using sObject Collections
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/platform/api-rest/guides/resources/resources-composite-sobjects-collections-create.md
canonical_url: https://developer.salesforce.com/docs/platform/api-rest/guide/resources-composite-sobjects-collections-create.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 72c3859a347bb2304f5520f9861470b73d477ba91fd1b694170e5d6df156b487
products:
  - REST API Developer Guide
  - Platform Developer Content
---

# Create Records Using sObject Collections

Use a POST request with sObject Collections to add up to 200 records, returning a list of SaveResult objects. You can choose whether to roll back the entire request when an error occurs.

-   The list can contain up to 200 objects.
-   The list can contain objects of different types, including custom objects.
-   Each object must contain an attributes map. The map must contain a value for `type`.

    **note:** Using sObject Collections to insert blob data requires more values in the attributes map. For more information, see [Using sObject Collections to Insert a Collection of Blob Records](https://developer.salesforce.com/docs/platform/api-rest/do-me/dome-sobject-insert-update-blob.md#using-sobject-collections-to-insert-a-collection-of-blob-records).

-   Objects are created in the order they’re listed. The SaveResult objects are returned in the order in which the create requests were specified.
-   If the request body includes objects of more than one type, they are processed as chunks. For example, if the incoming objects are `{account1, account2, contact1, account3}`, the request is processed in three chunks: `{{account1, account2}, {contact1}, {account3}}.` A single request can process up to 10 chunks.
-   You can’t create records for multiple object types in one call when one of the types is related to a feature in the Salesforce Setup area.

If the request isn’t well formed, the API returns a `400 Bad Request` HTTP Status. Fix the syntax of the request and try again. If the request is well formed, the API returns a `200 OK` HTTP Status. If an item was processed successfully, the `success` flag shows for that item. Error information is returned in the `errors` array.

## Syntax

**URI:** `/services/data/vXX.X/composite/sobjects`

**Formats:** JSON, XML

**HTTP Method:** POST

**Authentication:** `Authorization: Bearer token`

**Parameters**

|Parameter|Description|
|---------|-----------|
|`allOrNone`|Optional. Indicates whether to roll back the entire request when the creation of any object fails (`true`) or to continue with the independent creation of other objects in the request. The default is `false`.|
|`records`|Required. A list of sObjects. In a POST request using sObject Collections, set the `type` attribute for each object, but don’t set the `id` field for any object.|

**Note:** If the sObject Collections request is embedded in a Composite request, the Composite request’s `allOrNone` parameter can also affect the results. See [allOrNone Parameters in Composite and Collections Requests](https://developer.salesforce.com/docs/platform/api-rest/guide/resources-composite-allornone.md).

## Example

**Example Request**

```nolang
curl -X POST https://MyDomainName.my.salesforce.com/services/data/v68.0/composite/sobjects/ -H "Authorization: Bearer token" -H "Content-Type: application/json" -d "@exampleRequestBody.json"
```

**Example Request Body**

```nolang
{
   "allOrNone" : false,
   "records" : [{
      "attributes" : {"type" : "Account"},
      "Name" : "example.com",
      "BillingCity" : "San Francisco"
   }, {
      "attributes" : {"type" : "Contact"},
      "LastName" : "Johnson",
      "FirstName" : "Erica"
   }]
}

```

**Example Response Body**

```nolang
HTTP/1.1 200 OK

[
   {
      "id" : "001RM000003oLnnYAE",
      "success" : true,
      "errors" : [ ]
   },
   {
      "id" : "003RM0000068xV6YAI",
      "success" : true,
      "errors" : [ ]
   }
]

```

**Example Response Body (Some Items Failed and `allOrNone` is `false`)**

```nolang
HTTP/1.1 200 OK

[
   {
      "success" : false,
      "errors" : [
         {
            "statusCode" : "DUPLICATES_DETECTED",
            "message" : "Use one of these records?",
            "fields" : [ ]
         }
      ]
   },
   {
      "id" : "003RM0000068xVCYAY",
      "success" : true,
      "errors" : [ ]
   }
]

```

**Example Response Body (Some Items Failed and `allOrNone` is `true`)**

```nolang
HTTP/1.1 200 OK

[
   {
      "success" : false,
      "errors" : [
         {
            "statusCode" : "DUPLICATES_DETECTED",
            "message" : "Use one of these records?",
            "fields" : [ ]
         }
      ]
   },
   {
      "success" : false,
      "errors" : [
         {
            "statusCode" : "ALL_OR_NONE_OPERATION_ROLLED_BACK",
            "message" : "Record rolled back because not all records were valid and the request was using AllOrNone header",
            "fields" : [ ]
         }
      ]
   }
]

```

