---
schema_version: "1"
id: 01890a10cfbd67825b30cd42200f20eeaf692f067457e70855b340ad4f88908f
title: Navigate to a Record Create Page with Default Field Values
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/platform/aura-platform/guides/aura/components/components-navigation-dfv.md
canonical_url: https://developer.salesforce.com/docs/platform/aura-platform/guide/components-navigation-dfv.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: f20cf63ea4e2302f7d024ec253b3edf0c958c2c3a911f55686ac2021ad79ed36
products:
  - Lightning Aura Components Developer Guide
  - Platform Developer Content
---

# 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)`.

```nolang
<!-- auraNavigator.cmp -->
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes">
    <aura:attribute name="url" type="String"/>
    
    <!-- Specify the pageReference type. Only object is supported. -->
    <aura:attribute name="pageReference" type="Object"/>
    <aura:handler name="init" value="{! this }" action="{! c.init }"/>

    <!-- Implement the navigation service. -->
    <lightning:navigation aura:id="navService"/>

    <!-- pageReferenceUtil component -->
    <lightning:pageReferenceUtils aura:id="pageRefUtils"/>

    <!-- Generate a link to launch an account record create page. -->
    <a href="{!v.url}">New Account (Aura Link)</a> <br/>

    <!-- Launch an account record create page -->
    <a href="#" onclick="{!c.handleClick}">New Account (Aura PageRef)</a> <br/>
</aura:component>
```

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`.

```javascript
// auraNavigatorController.js
({
    init : function(cmp, event, helper) {
        var navService = cmp.find("navService");
        var pageRef = {
            type: "standard__objectPage",
            attributes: {
                objectApiName: "Account",
                actionName: "new"
            },
            state: {
            }
        }
        // Replace with your own field values
        var defaultFieldValues = {
            Name: "Salesforce, #1=CRM",
            OwnerId: "005XXXXXXXXXXXXXXX",
            AccountNumber: "ACXXXX",
            NumberOfEmployees: 35000,
            CustomCheckbox__c: true
        };
        pageRef.state.defaultFieldValues = cmp.find("pageRefUtils").encodeDefaultFieldValues(defaultFieldValues);
        cmp.set("v.pageReference", pageRef);
        var defaultUrl = "#";

        // Generate a Link for the Aura Link example
        navService.generateUrl(pageRef)
        .then($A.getCallback(function(url) {
            cmp.set("v.url", url ? url : defaultUrl);
        }), $A.getCallback(function(error) {
            cmp.set("v.url", defaultUrl);
        }));
    },
    
    // Navigate to the record create page for the Aura PageRef example
    handleClick : function(cmp, event, helper) {
        var navService = cmp.find("navService");
        var pageRef = cmp.get("v.pageReference");
        event.preventDefault();
        navService.navigate(pageRef);
    }
})
```

## 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.

**important:** We recommend that you always redirect and replace to remove the default field values from the URL and browser history.

This example uses `hasPageReference` to launch an account create page via an override action.

```nolang
<!-- auraNewAccountOverride.cmp -->
<aura:component implements="lightning:actionOverride,lightning:hasPageReference">

    <lightning:pageReferenceUtils aura:id="pageRefUtils"/>
    <lightning:recordEditForm 
                    objectApiName="Account"
                    onload="{!c.handleCreateLoad}">
        <lightning:messages />
        <lightning:inputField aura:id="nameField" fieldName="Name"/>
        <lightning:inputField aura:id="numOfEmpField" fieldName="NumberOfEmployees"/>
        <lightning:inputField aura:id="ownerIdField" fieldName="OwnerId"/>
        <lightning:inputField aura:id="customCheckField" fieldName="CustomCheckbox__c"/>
        <lightning:button class="slds-m-top_small" type="submit" label="Create new" />
    </lightning:recordEditForm>
</aura:component>
```

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.

**important:** 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.

This example is similar to prepopulating field values using `lightning:recordEditForm`, except that here the `defaultFieldValues` are dynamically generated when navigating to the form.

```javascript
// auraNewAccountOverrideController.js
({
    handleCreateLoad: function (cmp, event, helper) {
        var pageRef = cmp.get("v.pageReference");
        var defaultFieldValues =
        cmp.find("pageRefUtils").decodeDefaultFieldValues(pageRef.state.defaultFieldValues);
    
        var nameFieldValue = cmp.find("nameField").set("v.value", defaultFieldValues.Name);
        var numOfEmpFieldValue = cmp.find("numOfEmpField").set("v.value", defaultFieldValues.NumberOfEmployees);
        var ownerIdFieldValue = cmp.find("ownerIdField").set("v.value", defaultFieldValues.OwnerId);
        var customCheckFieldValue = cmp.find("customCheckField").set("v.value", defaultFieldValues.CustomCheckbox__c === 'true');
    }
})
```

**See Also**  


-   [*Component Library*: lightning:pageReferenceUtils Reference](https://developer.salesforce.com/docs/component-library/bundle/lightning:pageReferenceUtils/documentation)

