# How do you configure and build custom screen actions or quick actions using Lightning Web Components?

**Topic:** LWC · **Difficulty:** Medium · **Tags:** LWC, Quick Actions, Screen Actions

Read it on the site: https://www.forcechallenges.com/interview-questions/how-do-you-configure-and-build-custom-screen-actions-or-quick-actions-using-lightning-web-components

## Answer

**Basics:** Quick actions are buttons on record pages. A screen action opens a modal containing your component; a headless action runs code immediately with no UI (for example clone a record or call Apex). Note: `lightning/actions` is a module for events such as `CloseActionScreenEvent`; it does not contain wire adapters.

**How it works:** Metadata: in `.js-meta.xml` set `isExposed` true, target `lightning__RecordAction`, and `<targetConfig targets="lightning__RecordAction"><actionType>ScreenAction</actionType></targetConfig>`. In the component, declare `@api recordId` (and `@api objectApiName`). Setup: Object Manager > object > Buttons, Links, and Actions > New Action > Action Type "Lightning Web Component" > choose the component, label it, save; then add it to the layout under "Salesforce Mobile and Lightning Experience Actions" (or a Lightning page's highlights panel). For a headless action, export `@api invoke()`; it runs on click.

**Advanced / deep dive:** To close the modal from a screen action, dispatch `new CloseActionScreenEvent()` imported from `lightning/actions`. After changing data, refresh the page with `RefreshEvent` from `lightning/refresh` or `notifyRecordUpdateAvailable`. The modal's title comes from the action label, and Salesforce renders the header and Cancel chrome; for full control or custom footers, avoid trying to build your own modal inside a screen action. `recordId` may not be set during `connectedCallback`, so rely on a setter or `@wire` with `$recordId`. Headless actions cannot show UI beyond toasts, and `invoke()` may run each time the button is clicked, so make it idempotent and guard against double-clicks. These LWC actions are for Lightning Experience and the mobile app; support in Experience Cloud is limited, so verify.

**Code / config example:**
```javascript
import { LightningElement, api } from 'lwc';
import { CloseActionScreenEvent } from 'lightning/actions';
import { RefreshEvent } from 'lightning/refresh';
import { updateRecord } from 'lightning/uiRecordApi';

export default class CloseCaseAction extends LightningElement {
    @api recordId;

    async handleConfirm() {
        await updateRecord({ fields: { Id: this.recordId, Status: 'Closed' } });
        this.dispatchEvent(new RefreshEvent());
        this.dispatchEvent(new CloseActionScreenEvent());
    }
    handleCancel() { this.dispatchEvent(new CloseActionScreenEvent()); }
}
```

**Hidden gotchas & must-remember points:**
- `lightning/actions` has no wire adapters; it provides `CloseActionScreenEvent`.
- Without `actionType`, the component does not appear as an action.
- The action must be added to the layout or page to show up.
- `recordId` can be undefined early in the lifecycle.
- Headless `invoke()` has no UI and may run per click.
- Build your own modal only outside screen actions; inside one you already have a modal.

**Best practice:** Use a screen action for confirmation or input, a headless action for single-step operations, and always close and refresh explicitly.

---
Source: ForceChallenges · last updated 2026-11-02
