Get Record Create Defaults Examples

AVAILABLE API VERSION
API v68.0 and later

Get Create Defaults for an Object 

This example gets the default field values for creating an account record. Use rawValue for scalar fields. Use a single inline fragment with the ... on Object syntax for reference fields.

Get Account Create Defaults
1{
2  uiapi {
3    recordCreateDefaults(objectApiName: "Account") {
4      edges {
5        node {
6          recordTypeId
7          formFactor
8          fields {
9            apiName
10            rawValue
11            value {
12              __typename
13              ... on FieldDefaultReferenceValue {
14                id
15                displayValue
16                objectApiName
17              }
18            }
19          }
20        }
21      }
22      pageInfo {
23        hasNextPage
24        endCursor
25      }
26    }
27  }
28}

The previous query returns this partial response.

Response for Create Defaults for Account
1{
2  "edges": [
3    {
4      "node": {
5        "recordTypeId": "012000000000000AAA",
6        "formFactor": "LARGE",
7        "fields": [
8          { "apiName": "OwnerId",  "rawValue": "005xx000001X7oXAAS", "value": { "__typename": "IDValue" } },
9          { "apiName": "Owner",    "rawValue": null,                  "value": { "__typename": "FieldDefaultReferenceValue", "id": "005xx000001X7oXAAS", "displayValue": "Admin User", "objectApiName": "User" } },
10          { "apiName": "Name",     "rawValue": null,                  "value": { "__typename": "StringValue" } },
11          { "apiName": "Industry", "rawValue": null,                  "value": { "__typename": "PicklistValue" } }
12        ]
13      }
14    }
15  ]
16}

Get Create Defaults with Typed Field Values 

This example gets the default field values for a new opportunity record with a reusable fragment to get the typed value for each field.

Get Opportunity Create Defaults with Typed Values
1fragment FieldDefaultFragment on FieldDefault {
2  apiName
3  rawValue
4  value {
5    __typename
6    ... on IDValue            { id:   value }
7    ... on StringValue        { s:    value }
8    ... on BooleanValue       { b:    value }
9    ... on IntValue           { i:    value }
10    ... on LongValue          { l:    value }
11    ... on DoubleValue        { d:    value }
12    ... on PercentValue       { pct:  value }
13    ... on CurrencyValue      { cv:   value }
14    ... on DateValue          { date: value }
15    ... on DateTimeValue      { dt:   value }
16    ... on TimeValue          { time: value }
17    ... on TextAreaValue      { t:    value }
18    ... on LongTextAreaValue  { lta:  value }
19    ... on UrlValue           { u:    value }
20    ... on PicklistValue      { p:    value }
21    ... on MultiPicklistValue { mp:   value }
22    ... on LongitudeValue     { lov:  value }
23    ... on LatitudeValue      { lav:  value }
24    ... on FieldDefaultReferenceValue { id displayValue objectApiName }
25  }
26}
27
28{
29  uiapi {
30    recordCreateDefaults(objectApiName: "Opportunity") {
31      edges {
32        node {
33          recordTypeId
34          formFactor
35          fields {
36            ...FieldDefaultFragment
37          }
38        }
39      }
40    }
41  }
42}

Get Create Defaults in Template Mode 

This example uses TEMPLATE mode with optionalFields to return defaults only for the specified fields on the opportunity object.

Get Opportunity Create Defaults with TEMPLATE mode
1{
2  uiapi {
3    recordCreateDefaults(
4      objectApiName:  "Opportunity"
5      mode:           TEMPLATE
6      optionalFields: ["Opportunity.Name", "Opportunity.StageName", "Opportunity.CloseDate", "Opportunity.OwnerId"]
7    ) {
8      edges {
9        node {
10          recordTypeId
11          fields {
12            apiName
13            rawValue
14            value {
15              __typename
16              ... on FieldDefaultReferenceValue {
17                id
18                displayValue
19                objectApiName
20              }
21            }
22          }
23        }
24      }
25    }
26  }
27}

Get Create Defaults and Layout 

This example chains getting account create defaults with the account layout to minimize round trips. The two fields share multiple arguments, such as objectApiName and recordTypeId, and require consistency in query.

Get Account Create Defaults and Layout
1{
2  uiapi {
3    recordLayouts(
4      objectApiName: "Account"
5      mode:          CREATE
6      formFactor:    LARGE
7    ) {
8      edges {
9        node {
10          recordTypeId
11          sections {
12            heading
13            layoutRows {
14              layoutItems {
15                label
16                required
17                editableForNew
18                layoutComponents {
19                  apiName
20                  componentType
21                }
22              }
23            }
24          }
25        }
26      }
27    }
28
29    recordCreateDefaults(objectApiName: "Account") {
30      edges {
31        node {
32          recordTypeId
33          fields {
34            apiName
35            rawValue
36            value {
37              __typename
38              ... on FieldDefaultReferenceValue { id displayValue objectApiName }
39            }
40          }
41        }
42      }
43    }
44  }
45}

See Also 

Get Record Create Defaults