How to get record id in lightning:recordEditForm?

How to get record id in lightning:recordEditForm?

Component:

<aura:component >     
    <div class="slds-box slds-theme_default">   
        <lightning:recordEditForm  objectApiName = "Opportunity"  
                               onsuccess = "{! c.handleSuccess }">  
            <lightning:inputField fieldName="Name" />  
            <lightning:inputField fieldName="StageName" />  
            <lightning:inputField fieldName="CloseDate" />  
            <lightning:inputField fieldName="AccountId" />  
            <lightning:button class="slds-m-top_small"   
                              variant="brand"   
                              type="submit"   
                              name="update" label="Update" />  
              
        </lightning:recordEditForm>  
    </div>  
</aura:component>  

Component Controller:

({  
      
    handleSuccess : function(component, event, helper) {  
          
        var params = event.getParams();  
        alert(params.response.id);  
          
    }  
      
})  

Output:

Leave a Reply