Sub topic 1
What a Quick Action Is and When to Use an LWC
Prerequisites
Assume you know the basic structure of a Lightning web component (LWC), including its HTML template, JavaScript class, and js-meta.xml file. You should also understand @api, event handlers, Salesforce record pages, and page layouts.
A quick action is a button or menu command that helps a user complete a focused task. An LWC is a good fit when the task needs custom fields, validation, conditional behavior, or a specific save process that standard Salesforce actions cannot provide.
Screen Actions and Headless Actions
A screen action opens a dialog. The component displays controls, collects input, saves data, and closes the dialog. Use it when the user must review or enter information.
A headless action has no visible dialog. Salesforce calls the component's public invoke() method when the user clicks the action. Use it for an immediate operation, such as updating a status, sending a notification, or starting an integration.
| Action type | User interface | Main entry point | Typical use |
|---|---|---|---|
| Screen action | Dialog with fields and buttons | Component lifecycle and handlers | Edit a record value |
| Headless action | None | `@api invoke()` | Run an immediate operation |
Exposing the Component with js-meta.xml
The metadata file exposes the component to Salesforce. For a record quick action, use the lightning__RecordAction target. Set actionType to ScreenAction for a dialog. Use Action for a headless action.
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>60.0</apiVersion>
<isExposed>true</isExposed>
<targets>
<target>lightning__RecordAction</target>
</targets>
<targetConfigs>
<targetConfig targets="lightning__RecordAction">
<actionType>ScreenAction</actionType>
</targetConfig>
</targetConfigs>
</LightningComponentBundle>Getting the Record Context
Salesforce supplies the current record's ID through a public property:
import { LightningElement, api } from 'lwc';
export default class UpdateDescription extends LightningElement {
@api recordId;
@api objectApiName;
}Use recordId when reading or updating the record. objectApiName identifies its object, such as Account or Contact. A quick action created for a record page normally receives these values from the platform.
Exercise
Which action type should you choose for a button that immediately marks the current record as processed without asking for input?
Show answer
Choose a headless action and implement its public @api invoke() method.