[SalesForce] How to refresh the browser page in a lightning component

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? 🙂

Best Answer

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.

Related Topic