10

I have created a Lightning web component quick action for account object in the Summer 2021 sandbox org. This is the screen action and working fine, but I am not able to close the action using JavaScript. I know we can use $A.get("e.force:closeQuickAction").fire(); in the Aura Components, but what is the Lightning web component equivalent for this?

I tried to find the documentations for this but seems to be not available at this time.

4
  • 3
    I've let the Salesforce docs team know about the missing page. If you need this functionality today, go with the Aura wrapper technique. If you can wait until they get back to you, should only be a few days, we'll probably have an affirmative answer.
    – sfdcfox
    Commented May 9, 2021 at 19:24
  • @sfdcfox sure I will wait until few days Commented May 10, 2021 at 4:23
  • 1
    From the developer preview today, it looks like there is an undocumented "CloseActionScreenEvent" that hasn't made its way to the official docs yet, but I found an RFC that references it. Check out BritishBoyinDC's answer.
    – nbrown
    Commented May 21, 2021 at 16:29
  • 1
    New blog post references it now: developer.salesforce.com/blogs/2021/05/… Commented May 21, 2021 at 19:52

2 Answers 2

22

Per today's Summer 21 release webinar, you will need to do two things

Add a new import:

import { CloseActionScreenEvent } from 'lightning/actions';

Then add a simple method to close it:

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

You can then call that and it will close the quick action. More details here

H/T to Fabien Taillon for the heads up on this one

2
10

I found a workaround if you want to continue using the lwc quick action(as I do :)). You can use NavigationMixin and have it Navigate to the record page you're on.

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

I found it performs the same functionality as what an $A.get("e.force:closeQuickAction").fire().

5
  • Brilliant idea, thanks Commented May 14, 2021 at 2:10
  • Is there any refresh made to the page or it's only closing the popup? Commented May 17, 2021 at 13:00
  • @MartinLezer yes there is a refresh. Commented May 17, 2021 at 14:03
  • 1
    @RahulGawale thanks for the answer. I hope there will be a real feature for this in the future :( Commented May 17, 2021 at 14:53
  • I have not had success with this performing a refresh. Data updated by the action before closing the dialog does not show. Instead, I've resorted to: setTimeout(function(){window.location.reload(); }, 3000); I don't like it, but it seems to work.
    – Bryan
    Commented Oct 20, 2021 at 20:55

You must log in to answer this question.

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