Sub topic 2
Making the component available with isExposed
This chapter assumes you can create a Lightning web component (LWC) bundle with an HTML template, a JavaScript class and a metadata file. It also assumes you can deploy to an org with Salesforce CLI. Here you will learn how the isExposed flag controls whether Lightning App Builder can see your component.
What isExposed does
Every LWC bundle has a configuration file named <componentName>.js-meta.xml. The isExposed element in that file tells the platform whether the component is visible outside the bundle's own namespace and code.
true: the component can be used in tools such as Lightning App Builder, Experience Builder and Flow Builder, provided the targets allow it.false: the component can still be used inside other components, but admins cannot pick it in a builder.
New bundles created by the Salesforce CLI start with isExposed set to false. If you forget to change it, nothing is wrong with your code. The component simply stays hidden.
A minimal exposed component
This metadata file exposes the component and lists three page types where it can be placed.
<?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>Setting isExposed to true is necessary but not enough. The component also needs at least one target. The next chapters cover targets in detail. For now, treat isExposed as the master switch and targets as the list of places it can appear.
How the two settings work together
App Builder shows a component on a page only if both conditions hold:
isExposedistrue.- The page type being edited matches one of the component's targets.
A matching JavaScript class and template
The metadata file works with the component's own code. This class and template are enough to test the exposure.
import { LightningElement, api } from 'lwc';
export default class AccountSummaryCard extends LightningElement {
@api recordId;
@api objectApiName;
@api headerText = 'Summary';
@api maxItems = 5;
}<template>
<lightning-card title={headerText} icon-name="standard:account">
<div class="slds-var-p-around_medium">
<p>Record Id: {recordId}</p>
<p>Object: {objectApiName}</p>
<p>Max items: {maxItems}</p>
</div>
</lightning-card>
</template>Deploy and check
Deploy the bundle to your default org:
sf project deploy start --source-dir force-app/main/default/lwc/accountSummaryCardThen open a Lightning page in App Builder. The component appears in the Custom section of the components list, labeled with its masterLabel.
Common errors
| Symptom | Likely cause |
|---|---|
| Component is missing from the list | `isExposed` is `false`, or the deploy failed |
| Component appears on some page types only | The page type is not listed under `targets` |
| Deploy fails with a metadata error | A malformed or misplaced element in the `.js-meta.xml` file |
Exercise
A developer deploys a component with isExposed set to true and a target of lightning__RecordPage. An admin edits a Home page in App Builder and cannot find the component. Why?
Show answer
The Home page type is lightning__HomePage, and it is not listed in targets. isExposed makes the component visible, but App Builder only lists it on page types that match a target. Adding lightning__HomePage and redeploying fixes it.
Exercise
What value of isExposed does a freshly generated LWC bundle have, and what is the effect?
Show answer
It is false. The component works when used inside other components, but admins cannot select it in App Builder until you set it to true.