Record Type selection in $A.get(“e.force:createRecord”) in lightning

I’m using $A.get(“e.force:createRecord”) to display record create page for an object, but this doesn’t display record type selection screen, we have to pass it explicitly. Default salesforce lightning behavior when user clicks on new record button is it shows record type selection. How I can implement same behavior. I don’t want to build custom component for this.

Answer

Currently, it’s not possible select a record type in the createRecord component.
You can create a dropdown or something with the record types options and then call the createRecord component passing the record type.

Example

var createRecordEvent = $A.get("e.force:createRecord");
    createRecordEvent.setParams({
        "entityApiName": "Contact",
        "recordTypeId": ""
    });
    createRecordEvent.fire();

This a dropdown example for select the record type

<div class="source-center-slds" >
        <div class="slds-p-around--x-large">
            <ui:inputSelect class="slds-select_container myselector"  label="{!'Select ' + v.label +  ' Record Type: '}" aura:id="levels">
                <aura:iteration items="{!v.types}" var="item">
                    <ui:inputSelectOption class="slds-select" text="{!item.Id}" label="{!item.Name}"/>      
                </aura:iteration>
            </ui:inputSelect>
            <button class="slds-button slds-button--neutral slds-not-selected slds-m-top--medium" onclick="{!c.create}">New</button>
        </div>
    </div>

v.types is an array with the record types values

Attribution
Source : Link , Question Author : Soham , Answer Author : Carlos Iribar

Leave a Comment