Sub topic 3
Naming the component for admins: masterLabel and description
This chapter assumes you can read a basic LWC bundle (HTML template, JavaScript class, .js-meta.xml file) and that you can deploy to an org with Salesforce CLI. It covers the two metadata elements that decide how an admin sees your component in Lightning App Builder.
Why naming matters
Admins don't see your folder name or class name. They see a list of custom components in the App Builder palette, and they pick from it by label. A component named accountSummaryCard in code is easy for you to find, but the palette shows whatever the metadata file tells it to show.
Two elements in the .js-meta.xml file control this:
masterLabelis the display name shown in the component palette and in the page's component list.descriptionis a short text that explains what the component does.
Both are optional. Neither one affects whether the component is exposed. That is the job of isExposed and targets.
The masterLabel element
If you leave out masterLabel, App Builder falls back to the component's API name, which is the folder name in camelCase. For accountSummaryCard, an admin sees accountSummaryCard. That works, but it reads like code.
Set masterLabel to a human-friendly name:
<?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 admin now sees "Account Summary Card" in the palette. The component's API name does not change, so references from other components and from Lightning page metadata keep working.
The description element
description is plain text. Salesforce shows it in places where admins review component details, such as Setup and the metadata of a Lightning page. Use it to answer one question: when should an admin use this component?
Write it as a sentence about behavior, not about implementation. "Shows a titled card with the current record context" tells an admin what to expect. "LWC using lightning-card" does not.
Choosing good labels
Admins often work in orgs with dozens of custom components. A few habits keep the palette usable:
- Use title case and spell out words. Prefer "Account Summary Card" to "AcctSumm".
- Name the purpose, not the technology. Prefer "Open Cases List" to "Case Datatable LWC".
- Keep labels distinct. Two components both labeled "Summary" force admins to guess.
- Avoid renaming a label casually after release. Admins may recognize components by name, and a changed label makes existing pages harder to audit.
| Element | Shown to admins as | If omitted |
|---|---|---|
| `masterLabel` | Component name in the palette | The component's API name |
| `description` | Explanatory text for the component | No description is shown |
Where the elements sit in the file
Order inside LightningComponentBundle is not significant for these two elements, but a common convention is to place them after isExposed and before targets, as in the example above. Keeping that order makes files easy to scan across a project.
Deploying a label change
A label change is a metadata change, so you must redeploy the bundle:
sf project deploy start --source-dir force-app/main/default/lwc/accountSummaryCardThen reload App Builder. A cached page can keep showing the old label until you refresh.
Common errors
- Label unchanged after deploy. The browser still has the old App Builder page loaded. Refresh it, and confirm the deploy succeeded.
- Deploy fails with an XML error. An element is misspelled or not closed.
masterLabelis case-sensitive, somasterlabelis invalid. - Two components look identical in the palette. They share a label. Give each a distinct
masterLabel.
Exercise
A component in the folder openCasesList has no masterLabel. What does an admin see in the App Builder palette, and what change to which file fixes it?
Show answer
The admin sees the API name, openCasesList. Add <masterLabel>Open Cases List</masterLabel> to openCasesList.js-meta.xml, then redeploy the bundle and refresh App Builder.
Exercise
You add a masterLabel and a description to a component, but isExposed is false. Will the component show up in App Builder?
Show answer
No. masterLabel and description only control how a component is presented. The component must also have isExposed set to true and at least one target.