7

Whats the lwc equivalent of this aura event?

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

7

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.

0

call the refreshApex () method if you want to get result from the SF

import apexMethod from '@salesforce/apex/Namespace.Classname.apexMethod';
@wire(apexMethod, { apexMethodParams })
propertyOrFunction;

    // opportunitiesOverAmount.js
import { LightningElement, api, wire } from 'lwc';
import { refreshApex } from '@salesforce/apex';
import getOpptyOverAmount from '@salesforce/apex/OpptiesOverAmountApex.getOpptyOverAmount';
import updateOpptyStage from '@salesforce/apex/OpptiesOverAmountApex.updateOpptyStage';

export default class OpportunitiesOverAmount extends LightningElement {
    @api amount;

    @wire(getOpptyOverAmount, { amount: '$amount' })
    opptiesOverAmount;

    handleClick(e) {
        updateOpptyStage({
            stage: 'Won'
        })
        .then(() => {
            return refreshApex(this.opptiesOverAmount);
        })
        .catch((error) => {
            this.message = 'Error received: code' + error.errorCode + ', ' +
                'message ' + error.body.message;
        });
    }
}
  • This helps updating the value of @wire property. But $A.get('e.force:refreshView').fire(); is used to tell OTHER components that things need to refresh. – zaitsman Feb 22 at 1:15
  • 1
    Yes that is correct @zaitsman, I need to tell other components that things need to be refreshed. – user64922 Feb 25 at 6:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.