[SalesForce] Create New button on lightning Component

I have a lightning Component to display the Account and its Contact relationship in tree view using Accordion SLDS. On this page, I want to put "New Contact" button to create a contact record.

Is it possible to get the standard lightning experience popup to create a record from New button on lightning component?

I tried the below one, but no luck,

<ui:button label="New" press="{!c.createRecord}"/>

Controller

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

getting error:

$createRecord [Cannot read property 'setParams' of undefined]

Is there any way out there to get the standard lightning experience record creation page layout by clicking the New button in lightning component?.

Thanks in advance!

Best Answer

I resolved it. Am posting here to save other's time,

I was getting that error if am viewing the page from application preview. Then I placed a lightning component tab and try to click on the button, it is opening the record creation popup.

Related Topic