Sub topic 1
The metadata file that controls App Builder access
A Lightning web component can work perfectly and still be invisible to admins. Lightning App Builder only lists components that declare themselves available, and that declaration lives in one XML file. This chapter explains what the file is, what each part of the minimal version does, and how App Builder uses it. Later chapters cover targets, properties and targetConfigs in detail.
Prerequisites
This chapter assumes you have:
- Basic Lightning web component structure: an HTML template, a JavaScript class, and a metadata file.
- Familiarity with the Salesforce Setup UI and Lightning pages.
- A Salesforce org or sandbox where you can deploy code, with Salesforce CLI and VS Code set up.
- Basic XML syntax: elements, nesting, attributes, and namespaces.
What the metadata file is
Every Lightning web component is a folder (a bundle) that contains its source files. The metadata file is the one that tells Salesforce how to treat the bundle as a piece of metadata, not as code. It has the same name as the folder, followed by .js-meta.xml.
force-app/main/default/lwc/accountSummaryCard/
├── accountSummaryCard.html
├── accountSummaryCard.js
└── accountSummaryCard.js-meta.xmlThe file name must match the folder name exactly, including capitalization. If it does not, the deployment fails or the file is ignored. Salesforce DX creates the file for you when you run sf lightning generate component, but the generated version exposes nothing.
The HTML and JavaScript files define what the component does. The metadata file defines where and how Salesforce can use it. App Builder reads only the metadata, so a component that is missing the right entries does not appear in the component list, however good the code is.
The minimal file
This is the file for a component that admins can place on app, home and record pages:
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>60.0</apiVersion>
<isExposed>true</isExposed>
<masterLabel>Account Summary Card</masterLabel>
<description>Shows a titled card with the current record context.</description>
<targets>
<target>lightning__AppPage</target>
<target>lightning__HomePage</target>
<target>lightning__RecordPage</target>
</targets>
</LightningComponentBundle>The parts are:
- The XML declaration on the first line sets the version and encoding. Keep it as shown.
- The root element is
LightningComponentBundle. Itsxmlnsattribute is the Salesforce Metadata API namespace. If you misspell either one, deployment fails with a parse error. apiVersionsets the Salesforce API version the component runs against.isExposedcontrols whether App Builder can see the component.masterLabelanddescriptioncontrol how the component is presented to admins.targetslists the page types where the component can be placed.
apiVersion
apiVersion is required. It pins the component to a release of the platform, which keeps its behavior stable when Salesforce upgrades the org. Use a version your org supports. If you pick one that is newer than your org, the deployment fails.
Changing apiVersion later can change behavior, because some platform features only apply at or above certain versions. Treat a version bump as a code change and test it, not as paperwork.
isExposed: the on/off switch
isExposed is a boolean. Its default is false, which is why a freshly generated component does not show up in App Builder.
| Value | Effect |
|---|---|
| `false` or omitted | Other components can still use the component in their own templates. App Builder does not list it. |
| `true` | The component is exposed to the tools that read the metadata file, including App Builder. |
Setting isExposed to true is necessary, but it is not enough. App Builder also needs at least one entry under targets that matches the kind of page the admin is editing. A component with isExposed set to true and no targets is not listed in any page type.
A useful pattern follows from this. Many components are never meant to be placed by admins. Child components, helpers and shared UI pieces should keep isExposed as false, so the App Builder component list shows only what an admin can sensibly use.
masterLabel and description
masterLabel is the name admins see in the component list and in the page canvas. If you leave it out, App Builder falls back to the bundle's API name, such as accountSummaryCard. That works, but a readable label is better for admins. The label is a display string, so it can contain spaces and mixed case.
description is a short sentence shown to admins when they look at the component, for example in the component list. Write it for a person who has never seen your code. Say what the component shows and, if it matters, where it makes sense to place it.
Neither element affects how the component runs. You can change them after release without breaking any page that already uses the component, because pages refer to the component by its API name and not by its label.
How App Builder uses the file
When an admin opens App Builder, the tool queries the org's metadata and builds the component list from the bundles that qualify. The checks happen in order.
The third check applies only to record pages that restrict a component to certain objects. You will meet that in a later chapter. The first two checks are the ones that come from the minimal file in this chapter.
Connecting the file to the component class
The metadata file does not contain the component's logic, but it must agree with it. Properties that admins can configure are declared twice: once as @api properties in JavaScript, and once in the metadata file under targetConfigs. For now, it is enough to see the JavaScript half, which the metadata file will later point at:
import { LightningElement, api } from 'lwc';
export default class AccountSummaryCard extends LightningElement {
@api recordId;
@api objectApiName;
@api headerText = 'Summary';
@api maxItems = 5;
}The class name and the bundle name relate in a fixed way. The folder accountSummaryCard produces a component named c-account-summary-card in other templates, and the class uses the PascalCase form, AccountSummaryCard. The metadata file name follows the folder, not the class.
Deploying the file
Metadata changes reach the org only through a deployment. Deploy the whole bundle, not just the XML file, so the files stay consistent:
sf project deploy start --source-dir force-app/main/default/lwc/accountSummaryCardAfter a successful deployment, open or reload App Builder. The component appears under the Custom heading in the component list. If you have App Builder open during the deployment, reload the browser tab, because the component list is loaded when the editor starts.
Common mistakes with the file
These are the errors you are most likely to meet at this stage:
- Leaving
isExposedasfalse. The component deploys without errors and never appears. This is the most common cause of a missing component. - Exposing without targets. The flag is
true, but no page type is declared, so the component appears nowhere. - Misnamed file. A file called
accountsummarycard.js-meta.xmlin a folder namedaccountSummaryCarddoes not match, and the bundle fails to deploy or the metadata is ignored. - Wrong namespace or root element. Deployment fails with an XML parse error. Copy the root element from a working file instead of typing it.
- Invalid target name. Target values are case-sensitive and use double underscores, for example
lightning__RecordPage. A value likelightning_RecordPageis rejected at deployment. - Unsupported
apiVersion. A version higher than the org supports fails the deployment with a message about the API version.
What comes next
You now have the file that makes a component eligible for App Builder. The chapters that follow build on it in order. They cover which targets to choose, how @api properties become inputs in the property panel, how targetConfigs give each page type its own configuration, and how record pages pass recordId and objectApiName. The same file grows with each step. The structure you learned here, a root element holding flat settings and nested lists, stays the same.
Exercise
You deploy a new component with a valid .js-meta.xml that includes apiVersion, masterLabel and a targets list with lightning__RecordPage. The deployment succeeds, but the component is missing from App Builder. Which element do you check first, and why?
Show answer
Check isExposed. Its default is false, so if the element is missing or set to false, the component deploys successfully but App Builder does not list it. Set it to true, redeploy, and reload App Builder.
Exercise
A teammate renames the component folder from accountSummary to accountSummaryCard but leaves the metadata file as accountSummary.js-meta.xml. What problem do you expect, and what is the fix?
Show answer
The metadata file name must match the bundle folder name, so the file no longer matches. The deployment fails or the metadata is ignored, and the component is not exposed. Rename the file to accountSummaryCard.js-meta.xml and redeploy the bundle.
Exercise
A component has isExposed set to true and an empty targets section is omitted entirely. Will an admin see it on a Lightning record page? Explain.
Show answer
No. isExposed makes the component eligible, but App Builder also needs a target that matches the page type, such as lightning__RecordPage. With no targets, no page type lists the component.