5

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
    May 9 at 19:24
  • @sfdcfox sure I will wait until few days May 10 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
    May 21 at 16:29
  • 1
    New blog post references it now: developer.salesforce.com/blogs/2021/05/… May 21 at 19:52
5

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

1
  • finally it came in the light of day, thanks May 22 at 4:20
8

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().

4
  • Brilliant idea, thanks May 14 at 2:10
  • Is there any refresh made to the page or it's only closing the popup? May 17 at 13:00
  • @MartinLezer yes there is a refresh. May 17 at 14:03
  • 1
    @RahulGawale thanks for the answer. I hope there will be a real feature for this in the future :( May 17 at 14:53

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.