# A complete component — the three files, plus Flow and LWR variants

Target: Spring '26 (API 66.0). Sources: [Component Configuration File](https://developer.salesforce.com/docs/platform/lwc/guide/create-components-meta-file.html), [Configuration tags reference](https://developer.salesforce.com/docs/platform/lwc/guide/reference-configuration-tags.html), [Flow screen target](https://developer.salesforce.com/docs/platform/lwc/guide/targets-lightning-flow-screen.html).

The JavaScript is in the skill body (§2). This file has the other two files and the variants.

## 1. `orderSummary.html`

```html
<template>
    <lightning-card title={title} icon-name="standard:orders">
        <div class="slds-var-p-horizontal_medium">
            <template lwc:if={order}>
                <dl class="slds-dl_horizontal">
                    <dt class="slds-dl_horizontal__label">Status</dt>
                    <dd class="slds-dl_horizontal__detail">{status}</dd>
                </dl>
                <lightning-button
                    label="Approve"
                    variant="brand"
                    disabled={notApprovable}
                    onclick={handleApprove}></lightning-button>
            </template>

            <template lwc:elseif={error}>
                <div class="slds-text-color_error" role="alert">{message}</div>
            </template>

            <template lwc:else>
                <lightning-spinner alternative-text="Loading order" size="small"></lightning-spinner>
            </template>
        </div>
    </lightning-card>
</template>
```

Note the getter naming: templates cannot negate, so the JavaScript exposes `notApprovable` rather than the markup trying to write `!approvable`.

## 2. `orderSummary.js-meta.xml`

```xml
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>66.0</apiVersion>
    <isExposed>true</isExposed>
    <masterLabel>Order Summary</masterLabel>
    <description>Shows an order's status and lets an approver approve it.</description>
    <targets>
        <target>lightning__RecordPage</target>
        <target>lightningCommunity__Page</target>
        <target>lightningCommunity__Default</target>
    </targets>
    <targetConfigs>
        <targetConfig targets="lightning__RecordPage">
            <property name="title" type="String" label="Card title" default="Order summary"/>
            <objects>
                <object>Order__c</object>
            </objects>
        </targetConfig>
        <targetConfig targets="lightningCommunity__Default">
            <property name="title" type="String" label="Card title" default="Order summary"/>
            <property name="recordId" type="String" label="Order record Id"/>
        </targetConfig>
    </targetConfigs>
</LightningComponentBundle>
```

Rules this file encodes:

- `apiVersion` is required to save changes back to the org; keep it on the current release rather than letting it drift.
- `isExposed` is `true` only because the component is meant for builders. A child component used only by its parent stays `false` with no targets.
- `lightningCommunity__Page` puts the component in the Experience Builder palette; **`lightningCommunity__Default` is what makes its properties editable there**. Declaring only `__Page` gives admins a component they cannot configure.
- `<objects>` on the record-page config limits where App Builder offers the component.
- Every target used here exists in the documented list. There is no `lightning__ServiceCloud`.

## 3. The Apex controller it calls

```apex
public with sharing class OrderController {

    @AuraEnabled(cacheable=true)
    public static List<Order__c> getOpenOrders(Id accountId) {
        return [
            SELECT Id, Name, Status__c, Total__c
            FROM Order__c
            WHERE Account__c = :accountId AND Status__c != 'Closed'
            WITH USER_MODE
            ORDER BY CreatedDate DESC
            LIMIT 200
        ];
    }

    @AuraEnabled
    public static void approveOrder(Id orderId) {
        try {
            OrderService.approve(new Set<Id>{ orderId });   // bulk-safe service, USER_MODE inside
        } catch (Exception e) {
            IntegrationLogger.error('OrderController.approveOrder', e);
            throw new AuraHandledException('This order could not be approved. Reference ' + IntegrationLogger.lastRef());
        }
    }
}
```

`cacheable=true` on the read (so it can be wired, and it must contain no DML), plain `@AuraEnabled` on the mutation, `WITH USER_MODE` on the query, a real exception logged and a safe message returned.

## 4. Flow screen variant

```js
import { LightningElement, api } from 'lwc';
import { FlowAttributeChangeEvent, FlowNavigationNextEvent } from 'lightning/flowSupport';

export default class OrderPicker extends LightningElement {
    @api availableOrders;      // input from the flow
    @api selectedOrderId;      // output back to the flow

    handleSelect(event) {
        this.selectedOrderId = event.detail.value;
        this.dispatchEvent(new FlowAttributeChangeEvent('selectedOrderId', this.selectedOrderId));
    }

    handleNext() {
        this.dispatchEvent(new FlowNavigationNextEvent());
    }

    @api
    validate() {
        return this.selectedOrderId
            ? { isValid: true }
            : { isValid: false, errorMessage: 'Choose an order before continuing.' };
    }
}
```

```xml
<targets>
    <target>lightning__FlowScreen</target>
</targets>
<targetConfigs>
    <targetConfig targets="lightning__FlowScreen">
        <property name="availableOrders" type="@salesforce/schema/Order__c[]" label="Orders" role="inputOnly"/>
        <property name="selectedOrderId" type="String" label="Selected order" role="outputOnly"/>
    </targetConfig>
</targetConfigs>
```

`validate()` is what the flow calls when the user presses Next; returning `isValid: false` keeps them on the screen with the message.

## 5. LWR (Experience Cloud) notes

- There is no `recordId` injected on an LWR site page the way there is on a record page — pass it as a property or read it from the page reference.
- Navigation:

  ```js
  import { NavigationMixin } from 'lightning/navigation';

  this[NavigationMixin.Navigate]({
      type: 'comm__namedPage',
      attributes: { name: 'Order_Detail__c' },
      state: { orderId: this.recordId }
  });
  ```

  `comm__namedPage` for site pages, `standard__recordPage` / `standard__objectPage` where the site exposes records, `standard__webPage` for external URLs. `standard__app` and `standard__navItemPage` assume the internal app and do not work on a site.
- Guest users: what the component can read is decided by the site's guest user profile and sharing rules, not by the component. Test as a guest, not as yourself.
- Public pages are indexed and measured: keep the initial payload small, avoid a wire that fans out into several Apex calls, and budget for Lighthouse rather than for the internal app's tolerance.
