0

I have a lightning component which handles a event and performs subsequent dml operations. Once this is done, a toast message is displayed (success/ error etc.) I want to refresh the entire browser window after this. I tried force:refreshView, but it just refreshes the component.

Any help? :)

3 Answers 3

7

You can use standard JS way -

window.location.reload()

Please note you have to make a property call from window object obligately (not just location.reload()) because Lightning LockerService treats the global namespace differently and the window object there is a special wrapper around original one.

Have tested it inside one of my Lightning components under Chrome and IE 11 - it works.


As an alternative (but not recommended), you can try the old Lightning way with refresh event:

$A.get('e.force:refreshView').fire();

documentation is here

https://developer.salesforce.com/docs/atlas.en-us.212.0.lightning.meta/lightning/ref_force_refreshView.htm

But from my experience, it works smoothly not everywhere,
e.g. I encountered the next issue in one of the places:

Uncaught Action failed: one:recordHomeFlexipage$controller$refresh 
[Cannot read property 'Qi' of null] 

and there is no documentation entries for this event on API v43 and v44.

0

You could redirect it on success as described here:

navigateToMyComponent : function(component, event, helper) {
    var evt = $A.get("e.force:navigateToComponent");
    evt.setParams({
        componentDef : "c:myComponent",
        componentAttributes: {
            contactName : component.get("v.contact.Name")
        }
    });
    evt.fire();
}
2
  • Hello, I tried this. Thanks for your comment btw. I navigated to the sObject record. However it doesnt refresh the page and hence I cannot see the updated case record post the dml operation. I still have to manually refresh the browser page. :)
    – KLab
    Commented Nov 8, 2017 at 11:56
  • The referred link does not work anymore. Commented Mar 4, 2020 at 7:55
0

You can use location.reload() in the lightning web component to refresh the page.

location.reload()

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .