Create Record

force:createRecord

Displays the Full Record Create panel.

For Use In

Lightning Experience, Experience Builder Sites, Salesforce Mobile App

This event opens a page to create a record for the specified entityApiName, for example, "Account", or "myNamespaceMyObjectc".

We recommend implementing lightning:pageReferenceUtils instead and creating the object using lightning:navigation with the standard__object page type. This launches a record create page with fields prepopulated with default values.

For more information, see the Lightning Aura Components Developer Guide.

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. Provide recordTypeId as a separate field, not as part of defaultFieldValues. 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.

This event is handled by the one.app container. It’s supported in Lightning Experience, the Salesforce mobile app, and Aura-based Experience Builder sites. This event presents a standard page to create a record. That is, it doesn’t respect overrides on the object’s create action.

The following objects are not supported by force:createRecord:

  • ContractLineItem
  • EventRelation
  • OpportunityLineItem
  • OrderItem
  • QuoteLineItem
  • TaskRelation
  • WorkOrderLineItem

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.

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.

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.

Default values on dependent picklists are available on accounts, opportunities, cases, contacts, leads, and custom objects.

Date and time field values must use the ISO 8601 format. For example:

  • Date: 2017-07-18
  • Datetime: 2017-07-18T03:00:00Z

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.

NameDescriptionTypeDefaultRequired
defaultFieldValuesPrepopulates 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 prepopulated fields. Errors during saving that are caused by field access limitations do not display error messages.map
entityApiNameRequired. The API name of the custom or standard object, such as "Account", "Case", "Contact", "Lead", "Opportunity", or "namespace__objectName__c".string
recordTypeIdNon-null if recordTypes are enabled. Null means Master RecordType.string