Sub topic 3
Exposing the Component with js-meta.xml
A quick action can only use your Lightning web component (LWC) if the component's metadata file declares it. This chapter covers that file: which target to use, how actionType selects the action's behavior, and which mistakes keep a component out of the action picker.
This chapter assumes you know the basic LWC bundle structure (HTML template, JavaScript class, and js-meta.xml), have a Salesforce DX project, and can deploy metadata to an org.
What the metadata file does
Every LWC bundle has a js-meta.xml file. Salesforce reads it to decide where the component can be used. Without it, the component compiles but cannot appear in Setup, in App Builder, or as a quick action.
Three elements matter for quick actions:
isExposedmakes the component visible to Setup and builder tools. It must betrue.targetslists the places the component may be used. For a record quick action, the target islightning__RecordAction.targetConfigsholds settings for a specific target. Here it holdsactionType.
A screen action configuration
This file exposes a component as a record quick action that opens a screen.
<?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>Read it from top to bottom:
apiVersionsets the API version the component runs against.isExposedset totruemakes the component selectable.- The
targetentry nameslightning__RecordAction, which places the component on record pages as an action. - The
targetConfigentry has atargetsattribute. It must match the target name, or the setting is not applied to it. actionTypechooses how the platform runs the component.
Choosing actionType
The actionType value tells the platform whether to open a panel or run code silently.
| Value | Behavior | Component needs |
|---|---|---|
| `ScreenAction` | Opens a modal panel that shows your template | An HTML template with UI |
| `Action` | Runs with no visible UI (a headless action) | A public `invoke()` method |
To make a headless action, change one line:
<actionType>Action</actionType>The JavaScript must then expose invoke() with @api. Chapter 10 builds that out. For now, the key point is that the metadata and the class must agree. A component marked Action without an invoke() method does nothing when clicked.
Deploying and checking the result
After you save the metadata, deploy the bundle:
sf project deploy start --source-dir force-app/main/default/lwc/updateDescriptionThen open Setup and go to Object Manager. Choose the object, open Buttons, Links, and Actions, and start a new action. Set the action type to Lightning Web Component. Your component should appear in the list. Chapter 11 covers that creation flow in full.
Common errors
- Component missing from the picker. Check that
isExposedistrueand that the target islightning__RecordAction. A typo in the target name fails silently. - Mismatched target names. The
targetsattribute intargetConfigmust name a target that you also listed undertargets. - Wrong actionType spelling. Values are case sensitive.
screenactionis not valid. - Deployment rejects the file. Element order and spelling follow the metadata schema. Copy a known working file if validation fails.
- Wrong target for the scope.
lightning__RecordActionis for actions on a record. Global actions use a different target, covered in a later chapter.
Exercise
A developer deploys a component with isExposed set to true and the target lightning__RecordAction. The actionType is Action, and the class has no invoke() method. The action appears in Setup. What happens when a user clicks it, and how do you fix it?
Show answer
Nothing visible happens, because a headless action has no UI and the platform finds no invoke() method to call. Fix it by adding @api invoke() { ... } to the class. If the component was meant to show a panel, change actionType to ScreenAction instead.
Exercise
Which three elements of js-meta.xml must be set for a component to be available as a record quick action, and what value does each take?
Show answer
isExposed must be true. The targets list must include lightning__RecordAction. A targetConfig for that target must set actionType to either ScreenAction or Action.