5

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

How to do this.

0

2 Answers 2

4

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

0
2

If you are inside the lightning container ,there is a standard event to open lightning edit page

Here is the code

Component for button

<aura:component>
   <ui:button label="Edit Record" press="{!c.edit}"/>
</aura:component>

The JS helper

edit : function(component, event, helper) {
  var editRecordEvent = $A.get("e.force:editRecord");
   editRecordEvent.setParams({
    "recordId": component.get("v.contact.Id")
   });
  editRecordEvent.fire();
}

You must log in to answer this question.

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