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
punith narasimhapunith narasimha 

How to refresh a component when change and save the picklist values in lightning

 Hi friends
My requirement is place a component in opportunity detail page (get the record details by using  {!v.recordId}) when change and save the Stage(StageName) picklist values in details page  then my component is need to refresh
Here I don’t want to use any button ,link
So I just used  aura:handler    in this action function I used
$A.get('e.force:refreshView').fire();     but is not working 
location.reload();        it is working but problem is entire page will reload number of times i.e it is reload the page continuously it does not stop

    <lightning:input label="current record id" aura:id="recid" value="{!v.recordId}" />
    <aura:handler name="init" value="{!this}" action="{!c.show}" />

({
 
    show : function(component, event, helper)
    {
        var recid=component.find("recid").get("v.value");
        //alert(recid);
        var ledmethod=component.get("c.opprecordidmethod");
        ledmethod.setParams({
            idd:recid,
        }); 
        ledmethod.setCallback(this, function(res){
            if (res.getState() === "SUCCESS")
            {
                var resultval = res.getReturnValue();
                component.set("v.stagename",resultval);
                if(resultval == "Prospecting"){
                    component.set("v.Prospectingcurrent", "resultval");
                    
                }
                if(resultval == "Qualification"){
                    component.set("v.Qualificationcurrent", "resultval");
                    
                    component.set("v.Prospectingcomplete", "resultval");
                }
                 $A.get('e.force:refreshView').fire();     
                //location.reload();
            }
        });
        $A.enqueueAction(ledmethod);  
    }
})

Please help me friends

Thanks in advance

 
Best Answer chosen by punith narasimha
Maharajan CMaharajan C
hi Punith,

From the standard record save on detail page if you want to refresh the custom component then you have to use the force:refreshView event in handler. Don't fire the event from action it will not work.

So your component should be like below:

<aura:handler name="init" value="{!this}" action="{!c.show}" />
<aura:handler event=”force:refreshView” action=”{!c.show}” />
<lightning:input label="current record id" aura:id="recid" value="{!v.recordId}" />


https://egarakesh.wordpress.com/2017/04/30/salesforce-lightning-record-pages-and-forcerefreshview/

Thanks,
Maharajan.C


 

All Answers

Boss CoffeeBoss Coffee
It will continue to reload because the method is called it every time it loads, and it continuously does so because it reloads at the end of the callback. What is the use case for updating a stage on immediate load of a record page?
Maharajan CMaharajan C
hi Punith,

From the standard record save on detail page if you want to refresh the custom component then you have to use the force:refreshView event in handler. Don't fire the event from action it will not work.

So your component should be like below:

<aura:handler name="init" value="{!this}" action="{!c.show}" />
<aura:handler event=”force:refreshView” action=”{!c.show}” />
<lightning:input label="current record id" aura:id="recid" value="{!v.recordId}" />


https://egarakesh.wordpress.com/2017/04/30/salesforce-lightning-record-pages-and-forcerefreshview/

Thanks,
Maharajan.C


 
This was selected as the best answer
punith narasimhapunith narasimha
Thank You Maharajan it is working