function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ 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. 

https://developer.salesforce.com/docs/atlas.en-us.198.0.lightning.meta/lightning/ref_force_recordSaveSuccess.htm

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"
                implements="force:appHostable,
                            flexipage:availableForAllPageTypes,
                            force:hasRecordId">
    
    <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}" />
</aura:component>

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

Apex Controller:
public class editRecordSimulationController {

    @AuraEnabled
    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
deechandeechan
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?

Thanks!
 
thoriyasthoriyas
@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..

file:///home/t9l010/Pictures/Screenshot%20from%202019-07-22%2017-42-42.png