Sub topic 12
Deploying the component and adding it to a page
This chapter assumes you have a Lightning web component bundle with a .js-meta.xml file, isExposed set to true, at least one target, and a configured Salesforce CLI authorized to an org. It covers deploying the bundle and placing the component on a Lightning page.
Deploy the bundle
Deploy the whole component folder so the HTML, JavaScript, and metadata files go together. The command below deploys to your default org.
sf project deploy start --source-dir force-app/main/default/lwc/accountSummaryCardIf the deploy succeeds, the CLI lists the files it deployed. If it fails, read the error before you do anything else. Metadata errors, such as an unknown target or a property type that doesn't match, are reported at this step and stop the component from appearing in App Builder.
Check that you are deploying to the org you plan to open. Run sf org list to see which org is the default.
The flow below shows the steps from deploy to a saved page.
Open App Builder
You can create or edit a page from Setup.
- Open Setup and search for Lightning App Builder.
- Click New to create an app page, home page, or record page. You can also click Edit next to an existing page.
- Pick the page type that matches a target in your metadata file. Follow the prompts for template and name.
The page type you pick decides whether your component is listed. The example component lists lightning__AppPage, lightning__HomePage, and lightning__RecordPage. It will appear on all three page types.
To edit a record page quickly, open a record, click the gear icon, and choose Edit Page.
Place the component
In the builder, the left sidebar shows the Components panel.
- Find your component under Custom. It is listed by its
masterLabel, here "Account Summary Card". - Drag it into a region of the page canvas.
- Click the component on the canvas. The property panel opens on the right.
- Change the values. The example offers Header text on app and home pages, and also Maximum items on record pages.
- Click Save. For a new page, an activation prompt appears. For a record page, choose Activation and assign it as the org default, an app default, or a specific app, record type, and profile combination.
A saved page is not shown to users until it is activated. Activation is a separate step for home and record pages.
Check the result
Open a record page for an Account and look at the card. It should show the header text you set, the record ID, Account as the object name, and the maximum items value.
On an app page or home page, there is no record context. recordId and objectApiName are undefined, so the template prints blank values for them. This is expected.
If you change the component later, deploy again and refresh the builder tab. App Builder doesn't pick up new metadata until the page reloads. Saved property values stay on the page. If you rename or remove a property in the metadata file, the old value is dropped, so check pages that used it.
| Step | Where | What to check |
|---|---|---|
| Deploy | Terminal | The CLI reports success for all files |
| Find | Components panel | The component is under Custom with the right label |
| Configure | Property panel | The properties and defaults match `targetConfigs` |
| Activate | Activation dialog | The page is assigned to the intended audience |
Exercise
You deployed a component whose metadata lists only lightning__RecordPage. You open Lightning App Builder to edit a home page, and the component is not in the Components panel. Why, and what do you change?
Show answer
The home page type requires the lightning__HomePage target, and the component does not list it. Add <target>lightning__HomePage</target> to the targets list (and a matching targetConfig if you want properties there), deploy again, then reload App Builder.
Exercise
A record page for an Account shows your component, but the page is not visible to other users. What step is missing?
Show answer
The page has been saved but not activated. Open the page's Activation settings and assign it as the org default, app default, or an app, record type, and profile assignment.