Newer Version Available

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

Navigate to a Record Create Page with Default Field Values

The lightning:pageReferenceUtils component provides utilities for encoding default field values into a string. Pass this string into the pageReference.state.defaultFieldValues attribute on standard__objectPage page reference types.
To launch a record create page with prepopulated field values, use the lightning:pageReferenceUtils and lightning:navigation components together. The examples on this page show you how to do this using standard actions and override actions.

Launch an Account Record with Default Field Values Using a Standard Action

This example adds two standard action links that navigate to a record create page with default field values. The first link uses a URL that you generate using generateUrl(pageRef), and the second link navigates directly to the record create page using navigate(pageRef).
In your client-side controller, get defaultFieldValues from pageRef and pass them into encodeDefaultFieldValues(). When you click a link to create an account, encodeDefaultFieldValues() reads and encodes the values and passes them into a new standard__objectPage.

Handle Default Field Values Using an Override Action

With standard actions, the default field values pass through the URL to the object as a string, and the redirect and replace is handled for you. With override actions, the encoding is handled for you, but you are responsible for decoding the string of default field values from the URL and handling the redirect and replace.

We recommend that you always redirect and replace to remove the default field values from the URL and browser history.

Important

This example uses hasPageReference to launch an account create page via an override action.

The client-side controller reads the default field values from the state key and gets the encoded string. It then passes the string into decodeDefaultFieldValues() to decode it and retrieve the object.

All default field values are passed into the record create page as strings, regardless of field type. For example, NumberOfEmployees: 35000 is passed into the page as the string 35000 instead of a number field type. Boolean values are passed into the page as true or false strings.

Important

This example is similar to prepopulating field values using lightning:recordEditForm, except that here the defaultFieldValues are dynamically generated when navigating to the form.