Create a Record

AVAILABLE API VERSION
Beta v59.0–65.0
Generally available v66.0 and later

Use mutations to create a record. Within mutations, the RecordCreate field enables you to create all object types your Salesforce user has access to. Only objects supported by UI API are available for mutations.

Example Account Create Request 

To create a record, use RecordCreate with field values for the record you want to create.

A response is returned when record creation is successful. To define the fields you want the response body to return, use the Record field. You can return the Id and selected fields from your record creation.

For example, create an account with the required name field.

Create Account with Name Field
1mutation AccountExample{
2  uiapi {
3    AccountCreate(input: {
4      Account: {
5        Name: "Trailblazer Express"
6      }
7    }) {
8      Record {
9        Id
10        Name {
11          value
12        }
13      }
14    }
15  }
16}

Example Response on Account Record Creation 

The response body returns the fields you request under Record.

Response for Create Account with Name Field
1{
2  "data": {
3    "uiapi": {
4      "AccountCreate": {
5        "Record": {
6          "Id": "001RM000005fdQuYAI",
7          "Name": {
8            "value": "Trailblazer Express"
9          }
10        }
11      }
12    }
13  },
14  "errors": []
15}

Example Child Contact Create Request 

Given the account ID returned by the account record creation, create an associated contact for that account. This example uses the record ID from the example, 001RM000005fdQuYAI. Replace the account ID with your own.

Create Child Contact on Account
1mutation ContactExample{
2  uiapi {
3    ContactCreate(input: {
4      Contact: {
5        FirstName: "Appy"
6        LastName: "Bobcat"
7        Email: "appy@example.com"
8        AccountId: "001RM000005fdQuYAI"
9      }
10    }) {
11      Record {
12        Id
13        Name {
14          value
15        }
16        Email {
17          value
18        }
19      }
20    }
21  }
22}

Example Response on Child Record Creation 

The response body returns the fields you request under Record.

Response for Create Child Contact
1{
2  "data": {
3    "uiapi": {
4      "ContactCreate": {
5        "Record": {
6          "Id": "003RM000008B7H0YAK",
7          "Name": {
8            "value": "Appy Bobcat"
9          },
10          "Email": {
11            "value": "appy@example.com"
12          }
13        }
14      }
15    }
16  },
17  "errors": []
18}

Record Creation Guidelines 

Consider these guidelines for creating a record.

  • For compound fields, use the constituent fields. For example use FirstName and LastName instead of Name.
  • For numerical field values, such as integers or currency, use the raw values. For example, use 80000 instead of 80,000 and don’t include currency symbols.
  • Sending a create request with field values that don’t match the supported format returns a ValidationError. Use the appropriate format for the field, such as YYYY-MM-DD for date fields.
  • Sending a create request with duplicate values can return a DataFetchingException error. Review your duplicate rules and make sure you’re not creating a duplicate record.

See Also 

Send Mutation Requests