Activity › Forums › Salesforce® Discussions › How can I create an edit button in lightning component in salesforce?
-
How can I create an edit button in lightning component in salesforce?
Posted by Laveena on October 16, 2019 at 2:02 PMHow can I create an edit button in lightning component in salesforce?
Saddam replied 6 years, 7 months ago 3 Members · 2 Replies -
2 Replies
-
Hello,
you can make use of force:editRecord tag to Open the page to edit the record specified by recordId.By Onclicking of button it redirect to standard Modal popup edit page in Lightning Component by using force:editRecord.
example:-
Component:-
<aura:component implements=”flexipage:availableForAllPageTypes,lightning:actionOverride,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:appHostable” access=”global” >
<aura:attribute name=”recordId” type=”String” default=”0032800000dampDAAQ” />
<lightning:button label=”Edit Record” onclick=”{!c.edit}”/>
</aura:component>
Controller:-
({
edit : function(component, event, helper) {
var editRecordEvent = $A.get(“e.force:editRecord”);
editRecordEvent.setParams({
“recordId”: component.get(“v.recordId”)
});
editRecordEvent.fire();
}
})
- [adinserter block='9']
-
Hi,
You can take advantage of built-in events to display modals that let you create or edit records via an Aura component.
The force:createRecord and force:editRecord events display a create record page and edit record page in a modal based on the default custom layout type for that object.The following example contains a button that calls a client-side controller to display the edit record page. Add this example component to a record page to inherit the record ID via the force:hasRecordId interface.
<aura:component implements=”flexipage:availableForRecordHome,force:hasRecordId” >
<aura:attribute name=”recordId” type=”String” />
<lightning:button label=”Edit Record” onclick=”{!c.edit}”/>
</aura:component><aura:component implements=”flexipage:availableForRecordHome,force:hasRecordId” >
<aura:attribute name=”recordId” type=”String” />
<lightning:button label=”Edit Record” onclick=”{!c.edit}”/>
</aura:component>
Log In to reply.