1

I have created a quick action that loads an LWC. I want after a save button is clicked, the page is refreshed and the LWC popup closed.

I have tried using the following code but the after the refresh, the lwc is still opening.

Any way to avoid that?

updateOpptyPolicyDetails({ wrapper: parameterObject })
      .then((result) => {       
        this.template.querySelectorAll('lightning-combobox').forEach(each => {
          each.value = undefined;
        });
      this.template.querySelectorAll('lightning-input').forEach(each => {
        each.value = '';
        });
        const evt = new ShowToastEvent({
          title: 'Success',
          message: 'Saved sucessfully!',
          variant: 'success',
          mode: 'dismissable'
      });
        this.dispatchEvent(evt);

        this.message = result;
        this.error = undefined;
        console.log('Message ' + this.message);        

      }) 
      .then(() => {       
        this.closeQuickAction();
        
      })
      .then(() => {       
        window.location.reload();        
      })
      .then(() => {       
        this.closeQuickAction();
        
      })    
     
      .catch((error) => {
          this.message = undefined;
          this.error = error;
          console.log('Error msg ' + JSON.stringify(error));

      });

UPDATED Solution

 .then(() => {       
        this.closeQuickAction();
        
      })
      .then(() => {       
        getRecordNotifyChange([{recordId: this.recordId}]);
      })

1 Answer 1

0

In Lightning, which is a Single Page Application, the page's state is stored in the URL. When you navigate to a new page via a script, it causes an event handler to change the state of the app. In this case, opening a Quick Action encodes the open modal in the URL. When you reload the page, your script stops executing, and the new page is loaded. In other words, you're reloading the Quick Action as if the user had clicked the Refresh button in the browser.

If you need to reload the data on the page, use the getRecordNotifyChange method to inform the Lightning Data Service that record-aware components (force:hasRecordId and @api recordId) should be updated with data from the server. You should never need to use window.location.reload.

To answer your question directly: no. You can't reload and close the Quick Action at the same time.

1
  • Awesome! That worked! Thank you so much! Updated the post.
    – Pauline
    Oct 13, 2022 at 9:23

You must log in to answer this question.

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