I am using force:createRecord() event to open a new record creation window form lightning component.The functionality that I observed is :

  • If I mention recordTypeId Attribute, it is opening record creation window and deafulting the record type to the Id that I have mentioned.This is fine.

  • If I dont mention any record type Id attribute then it is opeing record creation window with the default recordtype for that profile which is also fine from logical perspective.

I am actually trying to show the record type selection screen for the users when I don't mention any recordTypeId attribute and pre-populate some values using defaultFieldValues Attribute.I would like to know if this is possible currently in lightning. I am using lightning component for showing record creation window because I want to create record conditionally based on some checks.

3 Answers 3


This post will definitely help you. Please check this link


This should be possible. I've modified the example from the doc here just slightly. Assume yourRecordTypeId is populated with the right Id.

var createRecordEvent = $A.get("e.force:createRecord");
   "entityApiName": "WhatEverObjectWithRecordTypes__c",
   "defaultFieldValues": {
         'RecordTypeId' : yourRecordTypeId,

I would use some lines in an apex controller to get the available Record Type Ids via a SOQL query together with their Names and possibly show that in a custom picklist dynamically. Or use any logic in JavaScript.

Be careful while deploying the code to different Org: Record Type Ids might be different even if the Name is the same.


You are going to need to create the record type selection dialog manually, then on-click of the "Next" button call force:createRecord and pass in the selection Id to the recordTypeId param.

As of writing this response there are several blogs online that outline how to get there. However none are using the lightning:overlayLibrary which is new and you should be using. Basically in pseudo-form:

<!-- RecordTypeSelector component -->
<component controller="RecordTypeSelectorController">
    <lightning:radioGroup options="{!v.recordTypes}" value="{!v.recordTypeValue}" name="recordTypes"/>
    <lightning:button label="Cancel" onclick="{!c.close}"/>
    <lightning:button label="Next" variant="brand" onclick="{!c.openNewRecordPage}"/>

and in the client-side controller:

openNewRecordPage : function(component, event, helper) {
    var rtId = component.get('v.recordTypeValue');
    if (rtId != null)
        var createRecordAction = $A.get('e.force:createRecord');
            'entityApiName' : component.get('v.objectName'),
            'recordTypeId' : rtId

        // close me

To open the component as a modal dialog use the following script in the caller:

openNewContactModal : function(component, event, helper) {
    $A.createComponent('c:RecordTypeSelector', {}, function(content, status) {
        if (status === 'SUCCESS') {
            var modalBody = content;
                header: 'New Contact',
                body: modalBody, 
                showCloseButton: true
  • 1
    Just be cautioned that as with most blog posts there are issues in the code that you have to fix (these days blogs get you clicks -nobody cares about quality). Some examples are the stuff you find on sfdcmonkey.com which are downright terrible to follow, but good for getting ideas/perspectives.
    – Mossi
    Commented Feb 10, 2018 at 0:05
  • The author for the above mentioned blog is right above this answer. Lol
    – SatyaV
    Commented Feb 10, 2018 at 0:21
  • @ArnoldJr. Lol well honestly I think the ideas posted are good however they lack refinement. That particular website I believe is a collection of posts by different bloggers -some are better than others. There are other blogs that are much worse.. Anyway I meant to give a word of caution based on my own past experience.
    – Mossi
    Commented Feb 10, 2018 at 1:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .