force:createRecord

Opens a page to create a record for the specified entityApiName, for example, “Account” or “myNamespace__MyObject__c”.

To display the record create page for an object, set the object name on the entityApiName attribute and fire the event. recordTypeId is optional and, if provided, specifies the record type for the created object. defaultFieldValues is optional and, if provided, specifies values to use to prepopulate the create record form.

This example displays the record create panel for contacts.
createRecord : function (component, event, helper) {
    var createRecordEvent = $A.get("e.force:createRecord");
    createRecordEvent.setParams({
        "entityApiName": "Contact"
    });
    createRecordEvent.fire();
}
Note

Note

This event is handled by the one.app container. It’s supported in Lightning Experience, Salesforce1, and Lightning communities. This event presents a standard page to create a record. That is, it doesn’t respect overrides on the object’s create action.

Prepopulating Field Values

The defaultFieldValues attribute lets you prepopulate the create record form with default or calculated field values. Prepopulated values can accelerate data entry, improve data consistency, and otherwise make the process of creating a record easier. Specify default field values as name-value pairs in a JavaScript object.

This example displays the record create panel for a contact with two fields prepopulated.
var createAcountContactEvent = $A.get("e.force:createRecord");
createAcountContactEvent.setParams({
    "entityApiName": "Contact",
    "defaultFieldValues": {
        'Phone' : '415-240-6590',
        'Account' : '001xxxxxxxxxxxxxxx'
    }
});
createAcountContactEvent.fire();
You can specify values for fields even if they’re not available in the create record form.
  • If the field is hidden because it’s not on the page layout, the value specified in defaultFieldValues is saved with the new record.
  • If the current user doesn’t have create access to the field, due to field-level security, attempts to save the new record result in an error.
Important

Important

Error messages can’t reference fields the current user doesn’t have access to. This constraint means the user won’t know why the error occurred or how to resolve the issue.

Firing the force:createRecord event tells the app to use the standard create record page. You can’t catch errors that occur there, or alter the create page interface or behavior, for example, to show an improved error message. For this reason, it’s essential to perform access checks in your own code, before firing the event.

You can’t prepopulate system-maintained fields, such as Id or record modification time stamps. Default values for these fields are silently ignored.

Prepopulating rich text fields is unsupported. It might work for simple values, but the internal format of rich text fields is undocumented, so setting complex values that include formatting is problematic. Use at your own risk.

Date and time field values must use the ISO 8601 format. For example:
  • Date: 2017-07-18
  • Datetime: 2017-07-18T03:00:00Z
Note

Note

While the create record panel presents datetime values in the user’s local time, you must convert datetime values to UTC to prepopulate the field.

Attribute Name Type Description Required?
entityApiName String The API name of the custom or standard object, such as “Account”, “Case”, “Contact”, “Lead”, “Opportunity”, or “namespace__objectName__c”. Yes
defaultFieldValues String Prepopulates fields on a record create panel, including fields not displayed on the panel. ID fields and rich text fields can’t be prepopulated. Users must have create access to fields with prepopulated values. Errors during saving that are caused by field access limitations don’t display error messages.
recordTypeId String The ID of the record type, if record types are available for the object.