[SalesForce] New button in Lightning

I have a lightning custom page and I need to include a New button to create a new record.

How to do this.

Best Answer

Create a new record in Lightning

You may want to opens the page to create a new 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 parameter and fire the event. recordTypeId is optional and, if provided, specifies the record type for the created object. This example displays the record create panel for contacts.

Button

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

Controller

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

For Reference