[SalesForce] force refresh (f5) of a page after LWC quick action

edit: resolved see code.

I have a quick action which updates data on the detail page, after hitting said button the page needs a full refresh.

Scenario on the account page the user clicks the quick action which generates other records while updating the account page, then those updates on the account page need to be visible to the user.

The problem is when i use

window.location.reload(true);

It simply starts the quick action over….but it does also refresh the page so that's not.

this[NavigationMixin.Navigate]({
          type: 'standard__recordPage',
          attributes: {
              recordId: this.recordId,
              objectApiName: 'Account',
              actionName: 'view'
           },
      });

This doesn't work at all, sure it directs you to the page but it doesn't refresh the data…..it always pulls cache data.

Anyone have an idea on how to redirect out of the lwc quick action to the record page URL and then reload the page not fetching cached data but new data.

modified code with eval("$A.get('e.force:refreshView').fire();") …still doesn't work, but the function does fire.

    @track newTicket;
    @track submitSuccess;
    @api 
    get recordId(){
        return this._recordId;
    }
    set recordId(value){
        this._recordId = value;
        if(this._recordId){
            this.submitDealsDesk();

        }
    }

    _recordId;
    isSubmitting = true;   
    
  
    
     submitDealsDesk(){
        createCase({ quoteId: this.recordId })
        .then(result => {
            this.newTicket = result;
            this.submitSuccess = true;
        })
        .catch(error => {
            this.error = error;
            this.submitSuccess = false;
        })
        .finally(() => {
            this.isSubmitting = false;
            this.callToast();
            this.refreshPage();
        });
    
        } 
    
    
     callToast(){
            if(this.submitSuccess == true){
                this.dispatchEvent(
                    new ShowToastEvent({
                        title: "deals desk ticket submitted ",
                        message: "deals desk ticket submitted " + this.newTicket,
                        variant: "success"    
                    })
                );
            } else if(this.submitSuccess == false){
                this.dispatchEvent(
                    new ShowToastEvent({
                        title: "error ",
                        message: "erorr during submission",
                        variant: "error"    
                    })
                ); 
            }
        }
    

    closeQuickAction() {
        this.dispatchEvent(new CloseActionScreenEvent());
    }  

    refreshPage(){
    setTimeout(()=>{
        eval("$A.get('e.force:refreshView').fire();"); 
        this.closeQuickAction();

}
,3000);}
       }

Best Answer

If you're about to use this answer in a managed package, then don't. The solution I am about to post is not Security-Review friendly.

However, adding this in your JS should refresh the entire page the component is placed on.

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

The "trick" above was how this was done in Aura (without the eval) but somehow there is no equivalent in LWC.

PS: Also, as it is undocumented, it may stop working at any time but it seems to be working for now

Related Topic