Activity Forums Salesforce® Discussions Refresh Lightning component on Opportunity record Edit Save (Standard Layout) Reply To: Refresh Lightning component on Opportunity record Edit Save (Standard Layout)

  • Piyush

    April 25, 2016 at 11:10 am

    Hello Danna,

    Here is the code from my test app. My use case was in context of the Accounts and contacts but it should apply to any object. As far as my understanding when ever an object is saved then the current view is refreshed. This is visible by the spinner that is displayed over the top panel of the object. I added a handler to my component that uses the force:refreshView ( and just recalled my init method but could call another method if need be. This basically ensured that any time the object that was hosting the component was refreshed that my component would also refresh as well.

    Here is the 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 event="force:refreshView" action="{!c.doInit}" />
    <aura:attribute name="recordId" type="string" />
    <aura:attribute name="accType" type="String" />
    <aura:attribute name="accObj" type="account" default="{ sObjectType: 'Account'}"/>
    <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.accObj.Type}" />

    Here is my 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 acc = response.getReturnValue();
    component.set("v.accType", acc.Type);
    component.set("v.accObj", acc)

    setOutput : function(component, event, helper) {
    var editRecordEvent = $A.get("e.force:editRecord");
    "recordId": component.get("v.recordId")

    Here it the APEX controller code:

    public class editRecordSimulationController {

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