+ Start a Discussion
Dave The GhostDave The Ghost 

Lightning force:editRecord Event handle Save

I am working with the force:editRecord event to handle the edit of a list of objects in a lightning component. I am able to return and display the list of objects each list item has an edit button that calls a function like what is displayed in this article:
https://developer.salesforce.com/docs/atlas.en-us.200.0.lightning.meta/lightning/ref_force_editRecord.htm (https://developer.salesforce.com/docs/atlas.en-us.200.0.lightning.meta/lightning/ref_force_editRecord.htm" target="_blank)
I've only been able to get this to work in a developer org if I add the component to an object page.

The problem is I need to update the list with the newley updated values but haven't been able to find any reference to handling the save event on the editRecord Modal popup. Any assistance would be great. 


Here is basic example of what I am trying to do. Adding the component to the account page I can click the button edit the record and hit save. The Account compact data  in the top of the page updates but what's in the component does not.

Component Code:
<aura:component controller="editRecordSimulationController"
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <aura:dependency resource="markup://force:editRecord" type="EVENT" />
    <aura:handler name="handleEdit" event="force:editRecord" action="{!c.doInit}" />
    <aura:handler name="handleSaveSuccess" event="force:recordSaveSuccess" action="{!c.doInit}" />
    <aura:attribute name="recordId" type="string" />
    <aura:attribute name="accType" type="String" />
    <ui:inputText label="Record Id" value="{!v.recordId}" required="true"/>
	<ui:button class="btn" label="Submit" press="{!c.setOutput}"/>
    <br />
    <br />
    <br />
    Account Type: <ui:outputText value="{!v.accType}" />

Component Controller Code:
    doInit : function(component, event, helper) {
        var recordId = component.get("v.recordId");
        var action = component.get("c.getTypeFromAccount");
            	recordId: recordId
        action.setCallback(this, function(response){
            var state = response.getState();
            if (state === "SUCCESS") {
                var accType = response.getReturnValue();
                component.set("v.accType", accType);
	setOutput : function(component, event, helper) {
        var editRecordEvent = $A.get("e.force:editRecord");
             "recordId": component.get("v.recordId")

Apex Controller:
public class editRecordSimulationController {

    public static string getTypeFromAccount(string recordId)
        Account acc = [select Type from Account Where Id = :recordId limit 1];
        return acc.Type;

Best Answer chosen by Dave The Ghost
Dave The GhostDave The Ghost
So I figured this out by adding a component event and registering and handling within the component and refreshing the value in the controller.

All Answers

Dave The GhostDave The Ghost
So I figured this out by adding a component event and registering and handling within the component and refreshing the value in the controller.
This was selected as the best answer
Hi Dave,

I am having similar issue. How did you add the component event? 

Do you know if this will work for a custom object too?
Would you be able to share the code?

@Dave The Ghost is there any event to handel cancel click ?
rishabh rathor 18rishabh rathor 18
hi Dave The Ghost, when i click on edit button then records in tableshow in above form and after edit , and click on save button records should save in table. plz help me..