Sub topic 7
Exposing properties in the App Builder property panel
This chapter assumes you can read a basic LWC bundle (template, class, metadata file) and know the isExposed flag and targets from earlier chapters. You also need basic XML syntax and an org where you can deploy.
How a property reaches the panel
A component property shows up in the App Builder property panel only when two things exist and share the same name:
- A public
@apiproperty in the JavaScript class. - A
<property>element in atargetConfigof the.js-meta.xmlfile.
The @api property makes the value settable from outside the component. The <property> element tells App Builder to draw an input for it. An @api property with no matching <property> still works in code, but admins cannot edit it.
Declaring the property in both places
The JavaScript side:
import { LightningElement, api } from 'lwc';
export default class AccountSummaryCard extends LightningElement {
@api recordId;
@api objectApiName;
@api headerText = 'Summary';
@api maxItems = 5;
}The metadata side lists the properties for each group of targets:
<?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>
<targets>
<target>lightning__AppPage</target>
<target>lightning__HomePage</target>
<target>lightning__RecordPage</target>
</targets>
<targetConfigs>
<targetConfig targets="lightning__AppPage,lightning__HomePage">
<property name="headerText" type="String" label="Header text" default="Summary" />
</targetConfig>
<targetConfig targets="lightning__RecordPage">
<objects>
<object>Account</object>
</objects>
<property name="headerText" type="String" label="Header text" default="Summary" />
<property name="maxItems" type="Integer" label="Maximum items" min="1" max="10" default="5" />
</targetConfig>
</targetConfigs>
</LightningComponentBundle>Here the app and home pages expose only headerText. The record page also exposes maxItems. Each target gets only the properties listed in its own targetConfig.
recordId and objectApiName are not listed. App Builder fills them in automatically on record pages, so they do not need panel fields.
Property types and attributes
The type attribute controls the input the admin sees. Common types are String (text box), Integer (number box) and Boolean (checkbox). The other attributes refine the field.
| Attribute | Effect |
|---|---|
| `label` | Text shown next to the field |
| `default` | Initial value when the admin first places the component |
| `required` | Admin must enter a value before saving the page |
| `min`, `max` | Bounds for an `Integer` field |
| `datasource` | Comma-separated choices for a `String` field, shown as a picklist |
A picklist example:
<property name="size" type="String" label="Card size" datasource="small,medium,large" default="medium" />Common errors
- Name mismatch.
name="headerText"must match the@apiproperty exactly, including case. A mismatch can produce a field that does nothing or a deployment error. - Property in the wrong targetConfig. If a property is listed only for the record page, it will not appear on the home page.
- Defaults in two places. The XML
defaultis what the admin sees in the panel. The JavaScript default applies only when no value is supplied. Keep them equal so behavior is predictable. - Missing target. A
targetConfigcan name only targets that are also in<targets>.
Deploy the bundle with:
sf project deploy start --source-dir force-app/main/default/lwc/accountSummaryCardExercise
An admin opens a record page in App Builder and sees the Account Summary Card, but there is no "Maximum items" field. The class has @api maxItems = 5;. What should you check in the metadata file?
Show answer
Check that a <property name="maxItems" ...> element exists inside the targetConfig whose targets attribute includes lightning__RecordPage. An @api property alone does not create a panel field. Also confirm the name matches exactly, then redeploy and reload App Builder.