Sub topic 3
Exposing the component with js-meta.xml
This chapter assumes you can already build a basic Lightning web component with an HTML template, a JavaScript class, and a js-meta.xml file. You should know the @api decorator, and you should have a Salesforce DX project you can deploy to an org. A component only becomes a quick action once its metadata file says so. This chapter covers that file.
Why the metadata file decides everything
A Lightning web component bundle is just code until the platform knows where it may be used. The js-meta.xml file is that declaration. It controls three things:
- Whether the component is visible to admin tools at all (
isExposed). - Which places it can be used (
targets). - How it behaves in each place (
targetConfigs).
For a quick action, the setting that matters most is actionType. It tells the platform whether to open a modal panel (a screen action) or to call a method with no visible interface (a headless action). The component's JavaScript has to match that choice, so the metadata and the class must agree.
The anatomy of an action's metadata
Here is the complete file for a screen 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>Each element has a specific job.
| Element | Purpose | If it is wrong |
|---|---|---|
| `apiVersion` | The API version the component runs against. It affects platform behavior and which features are available. | Newer features may be missing, or the component may behave like an older release. |
| `isExposed` | Makes the component selectable in Setup tools. | The component does not appear in the quick action's component list. |
| `targets` | Lists the places the component can be used. | The component is not offered for quick actions. |
| `targetConfigs` | Holds per-target settings. | A target that needs configuration is incomplete. |
| `actionType` | Chooses screen or headless behavior. | The panel opens when you expected none, or the reverse. |
The target: lightning__RecordAction
The target lightning__RecordAction makes the component available as an object-specific quick action. Object-specific means the action belongs to one object, such as Account, and runs against one record of that object. The platform passes that record's ID to the component, which the next chapter covers.
Because the target is specific to actions, a component that only declares it can be chosen only as a quick action. It will not show up in Lightning App Builder as a regular page component. If you want the same component on a record page and as an action, you need to declare more than one target. That also means the component must work in both places, and often it cannot. Keep action components separate from page components, and put shared logic in a utility module or a child component that both reuse.
The two action types
actionType accepts two values:
ScreenActionopens a modal panel and renders your template inside it. The user interacts with it and closes it.Actionis a headless action. The platform does not render a panel. It calls a publicinvoke()method on your component when the user clicks the action.
The following diagram shows how the value you choose leads to different runtime behavior.
The headless variant
A headless action uses the same file with one value changed:
<?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>Action</actionType>
</targetConfig>
</targetConfigs>
</LightningComponentBundle>The JavaScript class must then expose invoke():
import { LightningElement, api } from 'lwc';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
export default class NotifyRecord extends LightningElement {
@api recordId;
@api invoke() {
this.dispatchEvent(new ShowToastEvent({
title: 'Action ran',
message: 'Record ' + this.recordId + ' was processed',
variant: 'success'
}));
}
}Compare the two files. Only the actionType value changes in the metadata. In the JavaScript, the screen action has a template with a panel and handlers, and the headless action has a public method and no meaningful template. A headless component still needs an HTML file, because every LWC bundle has one. An empty <template></template> is enough.
How the metadata and the class must agree
The platform does not check that your JavaScript matches your declared actionType when you deploy. A mismatch only shows up when someone clicks the action. The table lists the usual outcomes.
| Metadata | Class | Result |
|---|---|---|
| `ScreenAction` | Template with `lightning-quick-action-panel` | Works as designed. |
| `ScreenAction` | `@api invoke()` only, empty template | An empty panel opens and the `invoke()` method is not called. |
| `Action` | `@api invoke()` | Works as designed. |
| `Action` | Template and handlers, no `invoke()` | Clicking does nothing useful. Nothing is rendered and no code runs. |
The failures are quiet. A deployment succeeds and the problem appears only in the browser. When an action misbehaves, check the metadata first, because it is a short file and the mistake is usually there.
Deploying and wiring it up
Deploy the bundle with the Salesforce CLI. From the root of your project:
sf project deploy start --source-dir force-app/main/default/lwc/updateDescriptionAfter the deployment, the component appears in Setup when you create a quick action. You create the action in Object Manager, under the object's Buttons, Links, and Actions section, and choose the action type "Lightning Web Component". The component list shows only components that are exposed and have the lightning__RecordAction target. Creating the action and adding it to a layout is covered in a later chapter. For now, remember the filter: if your component is missing from that list, the cause is almost always in js-meta.xml.
Common errors
Several mistakes account for most failures at this stage:
isExposedisfalseor missing. The component deploys without error but cannot be chosen in Setup. Set it totrue.- A typo in the target name.
lightning__RecordActionis case-sensitive, and it uses two underscores. A misspelled target is not an action target, so the component is not offered. - A
targetConfigwhosetargetsattribute does not match. The attribute must name a target you listed intargets. A mismatch leaves the configuration unused or causes a deployment error. - The wrong
actionTypefor the code. See the table above. Decide which behavior you want first, then write the matching class. - Changing
actionTypeafter the action exists. The quick action in Setup was created against the earlier configuration. After you redeploy, check the action in Setup and open and re-save it if it does not pick up the new behavior. Test it in a fresh browser session, because the platform caches component metadata. - Reusing a screen component as a headless one. The two types call different entry points, so the same class rarely serves both. Write two components.
Choosing between the two
Pick the type from the requirement, not from habit:
- Use
ScreenActionwhen you need input from the user, a confirmation step, or a form that shows results. - Use
Actionwhen the work needs no input, such as flagging a record, calling an Apex method with the current record ID, or showing a toast message.
A headless action is faster to build and feels more immediate to the user, but it gives them no chance to review or cancel. For anything destructive or hard to reverse, prefer a screen action with an explicit confirmation button.
Summary of the working model
The platform reads js-meta.xml to learn where your component may appear and how to run it. For a quick action, isExposed makes it visible, lightning__RecordAction marks it as an object action, and actionType selects the runtime path. Your JavaScript then has to supply what that path expects: a template for ScreenAction, or an invoke() method for Action.
Exercise
A teammate deploys a component whose js-meta.xml has isExposed set to true, the target lightning__RecordAction, and actionType set to Action. The class contains a full template with a Save button and a handleSave method, but no invoke() method. When a user clicks the quick action, nothing visible happens. Explain why, and name two valid ways to fix it.
Show answer
With actionType set to Action, the platform treats the component as headless. It does not render the template, and it looks for a public invoke() method, which does not exist, so no code runs. Fix 1: change actionType to ScreenAction so the platform opens a panel and renders the template with the Save button. Fix 2: keep Action and move the logic into an @api invoke() method, dropping the template's interactive parts. Choose the first fix if the user needs to enter or confirm anything.
Exercise
You deploy a screen action component, but it does not appear in the list of components when you create a quick action in Setup. Name three things in js-meta.xml you would check.
Show answer
Check that isExposed is true, that the targets list contains lightning__RecordAction spelled exactly with its case and double underscores, and that the targetConfig element's targets attribute names that same target. Also confirm the bundle deployed to the org you are viewing.