[SalesForce] refreshView for Lightning Web Component

Whats the lwc equivalent of this aura event?

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

Best Answer

I had this issue myself today as well. In my case, I had a Quick Action Lightning Aura Component which enveloped a Lightning Web Component (because there is currently no way of using a Lightning Web Component as a Quick Action)..

What I did is set up my Aura Component to catch 'close' events:

<!-- aura/auraComponent/auraComponent.cmp -->
<aura:component implements="force:lightningQuickAction,force:hasRecordId">
    <c:webComponent recordId="{!v.recordId}" onclose="{!c.handleClose}" />
</aura:component>

And process them with the events I would LIKE to throw from my Web Component:

// aura/auraComponent/auraComponentController.js
({
    handleClose: function() {
        $A.get('e.force:refreshView').fire();
        $A.get("e.force:closeQuickAction").fire();
    }
})

And in my Web Component I throw the following Custom Event to trigger the refresh & quick action close:

this.dispatchEvent(new CustomEvent('close'));

I know it's ugly, but at the time of writing I don't think there's a better way to refresh an underlying record page & close a Quick Action modal from a Lightning Web Component.

Related Topic