Activity Forums Salesforce® Discussions How can I create an edit button in lightning component in salesforce?

  • Yogesh

    Member
    October 17, 2019 at 7:00 am

    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();

    }

    })

  • Saddam

    Member
    October 17, 2019 at 7:25 am

    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.

Popular Salesforce Blogs

Popular Salesforce Videos