Sub topic 13
Troubleshooting: component or properties not showing
This chapter assumes you can build a basic Lightning web component and read its .js-meta.xml file. You should also have deployed code with Salesforce CLI and opened Lightning App Builder in Setup. Here you learn a repeatable way to find out why a component is missing from App Builder, or why its properties do not appear in the property panel.
A working model of the problem
App Builder shows a component only when several conditions line up. Each condition lives in a different place, so a failure usually has one specific cause.
- The bundle is deployed to the org you are looking at.
- The metadata file sets
isExposedtotrue. - The metadata file lists a target that matches the kind of page you are editing.
- If the page is a record page, any
objectsrestriction includes the page's object. - The form factor of the page is supported.
Properties add a second layer. A property appears in the panel only when the targetConfig for the current target declares it, and its declaration matches the @api property in the JavaScript class.
Component not listed in App Builder
Work through the checks in the order below. Earlier checks are cheaper and more common.
Check 1: Is the bundle in the org?
A deployment can fail without you noticing, especially when one file in the bundle has an error. Redeploy the bundle and read the output.
sf project deploy start --source-dir force-app/main/default/lwc/accountSummaryCardIf the command reports errors, fix them first. A component with an XML error in its metadata file is not saved, so nothing you check afterward matters until the deployment succeeds. Confirm that you deployed to the org you are logged in to in the browser. Running sf org list shows which org is your default.
Check 2: Is `isExposed` true?
Without <isExposed>true</isExposed>, a component can still be used inside other components, but App Builder will not list it. This is the most common cause of a missing component.
<?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__RecordPage</target>
</targets>
</LightningComponentBundle>Check the spelling and capitalization of the element. XML element names are case sensitive, so isexposed is rejected.
Check 3: Does a target match the page?
Each target maps to a kind of page. A component that lists only lightning__RecordPage appears when you edit a record page and is hidden when you edit a home page.
| Page you are editing | Target the component needs |
|---|---|
| App page | `lightning__AppPage` |
| Home page | `lightning__HomePage` |
| Record page | `lightning__RecordPage` |
The target name is also case sensitive and uses two underscores after lightning. A typo such as lightning_RecordPage fails at deployment, but a valid target for the wrong page type deploys fine and simply hides the component.
Check 4: Is the object restricted?
A record page targetConfig can contain an objects element. When it does, the component appears only on pages for the listed objects.
<targetConfig targets="lightning__RecordPage">
<objects>
<object>Account</object>
</objects>
</targetConfig>If you edit a Contact record page with this configuration, the component is missing. Add <object>Contact</object>, or remove the objects element to allow every object. Use the object's API name. For a custom object this ends in __c, for example Invoice__c.
Check 5: Is the form factor supported?
Pages have a form factor, such as desktop or phone. If you restrict supportedFormFactors and then preview the page in a form factor you left out, the component can be unavailable. Compare the form factor of the page with the declaration in the metadata file.
Check 6: Search by the right name
App Builder lists the component under the masterLabel value when one exists. Without it, App Builder shows the folder name, such as accountSummaryCard. If you renamed the label and cannot find the component under the old name, search for the new one. Custom components are grouped under Custom in the component list. Reload the App Builder browser tab after a deployment, because the list is loaded when the editor opens.
Properties not showing in the property panel
If the component appears but its properties do not, the cause is almost always in targetConfigs.
Cause 1: No property declaration for the target
An @api property in JavaScript is not shown to admins by itself. It becomes configurable only when a <property> element for the matching target declares it. The JavaScript below declares four public properties.
import { LightningElement, api } from 'lwc';
export default class AccountSummaryCard extends LightningElement {
@api recordId;
@api objectApiName;
@api headerText = 'Summary';
@api maxItems = 5;
}Only headerText and maxItems should be configurable. recordId and objectApiName are filled in by the record page and need no declaration.
Cause 2: The property is in the wrong targetConfig
Each targetConfig applies only to the targets listed in its targets attribute. In the example below, maxItems is declared only for record pages, so it will not appear on a home page.
<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>If an admin expects maxItems on a home page, add the property to the first targetConfig, or add a separate one for the target. Each target should appear in at most one targetConfig.
Cause 3: The name does not match the JavaScript
The name attribute in the XML must equal the @api property name exactly, including case. maxitems does not match maxItems. A mismatch can cause a deployment error or a property that never reaches the component.
Cause 4: The property is not public
A field without @api is private. Add the decorator, or the value cannot be set from outside. Also check that you did not mark the property with @track or leave it as a plain field by mistake.
Cause 5: The type or attribute is wrong
The type attribute decides which control appears in the panel. Common types are String, Integer and Boolean. A datasource works with String properties and turns the field into a picklist.
<property name="size" type="String" label="Card size" datasource="small,medium,large" default="medium" />If you set min or max on a String, they are not meaningful. If default is outside the min and max range for an Integer, the value is invalid. Keep the default value inside the allowed range and make it one of the choices when you use datasource.
Cause 6: A stale page
When you change a property declaration, existing pages do not always show the new value right away. Reload App Builder and reselect the component on the canvas. If you remove a property that admins already set, the saved value stays on the page but has no effect.
Values that look wrong at run time
Sometimes the panel is correct but the component shows the wrong thing.
recordIdis undefined. The component is on a home or app page, where no record exists. Only record pages setrecordIdandobjectApiName. Guard against empty values in your code.- A number arrives as text. Check that
type="Integer"is used and notString. - The default never applies. A default in the metadata file sets the panel value. A default in JavaScript, such as
headerText = 'Summary', is the fallback when no value is set. Keep both the same to avoid confusion.
A short diagnostic routine
- Redeploy the bundle and read the whole output.
- Open the metadata file and confirm
isExposed, the target and anyobjectsentry. - Reload App Builder and search for the
masterLabelvalue. - Select the component on the canvas and compare the panel with the
targetConfigfor that page type. - Compare each property
namewith its@apifield.
Exercise
You deployed a component with targets lightning__RecordPage and lightning__HomePage, and a targetConfig for lightning__RecordPage that has <objects><object>Account</object></objects>. It appears on an Account record page but not on a Contact record page. The home page shows it, but without the maxItems property that you declared in the record page targetConfig. What two changes would you make so that it appears on Contact pages and so that maxItems is configurable on the home page?
Show answer
Add <object>Contact</object> to the objects element (or remove the element) so Contact record pages list the component. Then declare maxItems in a targetConfig that includes lightning__HomePage in its targets attribute, because properties apply only to the targets listed on their own targetConfig. Redeploy and reload App Builder.
Exercise
A component's metadata file declares <property name="maxitems" type="Integer" />, but the JavaScript has @api maxItems = 5;. What is wrong, and how do you fix it?
Show answer
The name attribute must match the @api property name exactly, including case. Change maxitems to maxItems in the metadata file and redeploy.