Create Headless Quick Actions

A headless quick action executes custom code in a Lightning web component. Unlike a screen action, a headless action doesn’t open a modal window.

To enable your component to be used as a headless quick action, configure a target. See Configure a Component for Quick Actions.

Unlike other Lightning web components on record pages, LWC quick actions don’t pass in recordId in connectedCallback(). If you need access to recordId, set the value of recordId in your code.

In your Lightning web component, always expose invoke() as a public method for headless quick actions. The invoke() method executes every time the quick action is triggered.

Create an empty template for your Lightning web component.

To prevent the quick action from being executed multiple times in parallel in long-running actions, add an internal boolean flag.

The return type of invoke() is void. Returning a Promise makes your method asynchronous, but the returned Promise is ignored.

This code uses a boolean flag to block a double execution and a Promise to wait for the sleep to finish. Even though the return type is void, the code executes asynchronously.

To navigate to another page, record, or list in Lightning Experience, use the navigation service.

This example navigates to the contact home page.

See Navigate to Pages, Records, and Lists.

You can dispatch a custom event from a quick action. This example dispatches two toasts sequentially using the event provided by the lightning/platformShowToastEvent module.

See Toast Notifications and Communicate with Events.