# sObject Tree Request Body

Describes a collection of sObject trees to create with the sObject Tree resource.

:::important
Where possible, we changed noninclusive terms to align with our company value of Equality. We maintained certain terms to avoid any effect on customer implementations.
:::

## sObject Tree Collection Input

The request body contains a `records` collection that includes sObject trees.

**Properties**

| Name      | Type                 | Description                                                                                                                          | Required or Optional |
| --------- | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------ | -------------------- |
| `records` | sObject Tree Input[] | Collection of record trees to create. Each tree’s root record type must correspond to the sObject specified in the sObject Tree URI. | Required             |

**Root XML Tag:** `<SObjectTreeRequest>`

**JSON example**

```nolang
{
"records" :[{
    "attributes" : {"type" : "Account", "referenceId" : "ref1"},
    "name" : "SampleAccount",
    "phone" : "1234567890",
    "website" : "www.salesforce.com",
    "numberOfEmployees" : "100",
    "industry" : "Banking",
    "Contacts" : {
      "records" : [{
         "attributes" : {"type" : "Contact", "referenceId" : "ref2"},
         "lastname" : "Smith",
         "title" : "President",
         "email" : "sample@salesforce.com"
         },{         
         "attributes" : {"type" : "Contact", "referenceId" : "ref3"},
         "lastname" : "Evans",
         "title" : "Vice President",
         "email" : "sample@salesforce.com"
         }]
      }
    },{
    "attributes" : {"type" : "Account", "referenceId" : "ref4"},
    "name" : "SampleAccount2",
    "phone" : "1234567890",
    "website" : "www.salesforce2.com",
    "numberOfEmployees" : "100",
    "industry" : "Banking"
     }]
}
```

**XML example**

```nolang
<SObjectTreeRequest>
    <records type="Account" referenceId="ref1">
        <name>SampleAccount</name>
        <phone>1234567890</phone>
	       <website>www.salesforce.com</website>
	       <numberOfEmployees>100</numberOfEmployees>
	       <industry>Banking</industry>
	       <Contacts>
	           <records type="Contact" referenceId="ref2">
	               <lastname>Smith</lastname>
		              <title>President</title>
		              <email>sample@salesforce.com</email>
	           </records>
	           <records type="Contact" referenceId="ref3">
	  	            <lastname>Evans</lastname>
	  	            <title>Vice President</title>
	  	            <email>sample@salesforce.com</email>
	           </records>
	       </Contacts>
    </records>
    <records type="Account" referenceId="ref4">
        <name>SampleAccount2</name>
	       <phone>1234567890</phone>
	       <website>www.salesforce2.com</website>
	       <numberOfEmployees>100</numberOfEmployees>
	       <industry>Banking</industry>
    </records>
</SObjectTreeRequest>
```

## sObject Tree Input

An sObject tree is a recursive data structure that contains a root record, its data, and its child records represented as other sObject trees.

**Properties**

| Name                   | Type                          | Description                                                                                                                                                                                                                                                                                                                                                                                                            | Required or Optional |
| ---------------------- | ----------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------- |
| `attributes`           | Collection                    | Attributes for this record. The `attributes` property contains two required subproperties: `type` (this record’s type) and `referenceId` (reference ID for this record). The ID is case-sensitive and must be unique in the context of the request. Values must start with an alphanumeric character and contain only letters, numbers, or underscores (’_’). In XML, include attributes inside the `records` element. | Required             |
| Required object fields | Depends on field              | Required fields and field values for this record.                                                                                                                                                                                                                                                                                                                                                                      | Required             |
| Optional object fields | Depends on field              | Optional fields and field values for this record.                                                                                                                                                                                                                                                                                                                                                                      | Optional             |
| Child relationships    | sObject Tree Collection Input | This record’s child relationships, such as an account’s child contacts. Child relationships are either master-detail or lookup relationships. To view an object’s valid child relationships, use the sObject Describe resource or Schema Builder. The value of this property is an sObject Tree Collection Input that contains child sObject trees.                                                                    | Optional             |

**Root XML Tag:** `<records>`

**JSON example**

```nolang
{
"attributes" : {"type" : "Account", "referenceId" : "ref1"},
"name" : "SampleAccount",
"phone" : "1234567890",
"website" : "www.salesforce.com",
"NumberOfEmployees" : "100",
"industry" : "Banking",
"Contacts" : {
  "records" : [{
     "attributes" : {"type" : "Contact", "referenceId" : "ref2"},
     "lastname" : "Smith",
     "title" : "President",
     "email" : "sample@salesforce.com"
      },{         
     "attributes" : {"type" : "Contact", "referenceId" : "ref3"},
     "lastname" : "Evans",
     "title" : "Vice President",
     "email" : "sample@salesforce.com"
     }]
  }
}
```

**XML example**

```nolang
<records type="Account" referenceId="ref1">
    <name>SampleAccount</name>
    <phone>1234567890</phone>
    <website>www.salesforce.com</website>
    <numberOfEmployees>100</numberOfEmployees>
    <industry>Banking</industry>
    <Contacts>
        <records type="Contact" referenceId="ref2">
	           <lastname>Smith</lastname>
	           <title>President</title>
	           <email>sample@salesforce.com</email>
	       </records>
	       <records type="Contact" referenceId="ref3">
     	      <lastname>Evans</lastname>
     	      <title>Vice President</title>
     	      <email>sample@salesforce.com</email>
	       </records>
    </Contacts>
</records>
```
