Activity Forums Salesforce® Discussions How to refresh a lightning component after a record is saved ?

  • Piyush

    Member
    September 10, 2019 at 4:45 am

    Hi Hariom,

    You can use this code to refresh a lightning component after a record is saved:-

    <aura:component controller="editRecordSimulationController"
                    implements="force:appHostable,flexipage:availableForAllPageTypes,force:hasRecordId,force:hasSObjectName">
        
        <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}" />
    </aura:component>
    ({
        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 acc = response.getReturnValue();
                    component.set("v.accType", acc.Type);
                    component.set("v.accObj", acc)
                }
            });
            
            $A.enqueueAction(action);
        },
    	setOutput : function(component, event, helper) {
            var editRecordEvent = $A.get("e.force:editRecord");
            editRecordEvent.setParams({
                 "recordId": component.get("v.recordId")
            });
            editRecordEvent.fire();
    	}
    })

     

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos