+ Start a Discussion
Admin DEV 13Admin DEV 13 

$A.get('e.force:refreshView').fire() did not refresh the record detail component

Hi,
I create a lightning component for the lightning experience record pages. In the customize record page, I drag standard Record Detail component and my componont to the page. In my component, I update some fields of a record. After I save those field, I fire up the e.force:refreshView event. But the standard record detail component did not refresh to show the new value of those field. Is there any way to force to refresh the standard record detail component?

 
NagendraNagendra (Salesforce Developers) 
Hi,

You are not supposed to give same name to the apex controller's method and the function which is called on click. Also, you should pass event along with the component in the same.

Please find the code below:-

Controller:-
save : function(component, event) {                
        var action = component.get("c.apexSave"); 
        action.setCallback(this, function(action) {                
           $A.get('e.force:refreshView').fire(); 
        }); 
        $A.enqueueAction(action); 
    }

Note save and apexSave.

The server-side action is also provided by the “c” value provider. This is the same value provider that provides the JavaScript controller event handler which handles the press event of the button and the init event. Because of this, you need to make sure that you do not name your Apex controller methods with the same name as your JavaScript controller methods. It’s easy to make the mistake of naming them same because it is natural to want to be consistent in naming.

Source:- Salesforce1 Lightning Components – Working with Controllers
You may use an aura handler to make sure that whether it has been refreshed successfully.
 
<aura:handler event="force:refreshView" action="{!c.isRefreshed}" />

Hope this helps.

Best Regards,
Nagendra.P
Priyanka S 27Priyanka S 27
Hi,

You need to fire the event upon checking up whether the server returns the success response or not. use the below code snippet.

action.setCallback(this, function(response) {
if(response.getState() === SUCCESS){
$A.get('e.force:refreshView').fire();
}
});

Let me know if you have any questions. Mark the answer as best if you could resolve this.

Regards,
Priyanka S
 
Dudu NatoDudu Nato

I'm using force:editRecord in my component and once the record is save I call $A.get('e.force:refreshView').fire();

All the events are being fired, however, the component doesn't really reload. How am I sure of that? Because I have a trigger that changes the RecordType and that RecordType is assigned to a different layout. After the record is saved and I refresh the page by myself the layout is changed.

Any ideia?

Thanks

Aboo ThahirAboo Thahir
Hi,

Please do like the below:-
your js controller be like:-
 
saveAccount : function(component,event,helper){
        
        var saveAccountAction = component.get("c.accountSaved");
        // your code to send contact details to server
        
        actionSave.setCallback(this, function(saveAccountAction) {
            if (saveResult.state() === "SUCCESS") {
                //contact saved Successfully
                //Fire the refresh view event to update Account detail view
                $A.get('e.force:refreshView').fire();
                
            }else if (saveResult.state() === "ERROR") {
                console.log("Error Saving Contact ");
            } 
        });
        
        $A.enqueueAction(saveAccountAction);
    },
    /*page refresh after data save*/
    
    isRefreshed: function(component, event, helper) {
        location.reload();
    },
    /*page refresh after data save*/



Please don't forget to give the below in your component:-
 
<aura:handler event="force:refreshView" action="{!c.isRefreshed}" />

Change it according to your needs.
Hope this worked.
Please mark it as the best answer.

Thanks and regards,
Aboo




 
Ajay K DubediAjay K Dubedi
Hi,

To reload a view, run Location.reload();, which reloads all data for the view.
This example refreshes the view after an action is successfully completed.

action.setCallback(this, function(response) {
if(response.getState() === SUCCESS){
    Location.reload();
}
});

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
 
Aman Chawla 2Aman Chawla 2
I added 
location.reload();

to reload my entire page. Works like a charm. Love the native javascript :) 
pkulkarnipkulkarni
what Aboo has mentioned is working, I tried that.. thanks