Sub topic 2
Exposing a component with the lightning__FlowScreen target
This chapter assumes you can build a basic Lightning web component (LWC) with a template, a JavaScript class, and @api properties. It also assumes you know what a screen flow is and how to deploy metadata with Salesforce DX or the Developer Console.
A component does not appear in Flow Builder by default. You make it available by editing its configuration file, <componentName>.js-meta.xml. This chapter covers the parts of that file that expose a component to screen flows.
What the meta.xml file controls
Every LWC bundle has a meta.xml file. Salesforce reads it to decide where the component can be used. For flows, three things matter:
isExposedmust betrue. If it isfalse, the component can't be used in Flow Builder or other builder tools.targetslists the places the component can go. Flow screens uselightning__FlowScreen.targetConfigsholds settings that apply to one target, such as the properties the flow can set or read.
A minimal exposed component
This file exposes a component called Quantity Picker to screen flows:
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>60.0</apiVersion>
<isExposed>true</isExposed>
<masterLabel>Quantity Picker</masterLabel>
<targets>
<target>lightning__FlowScreen</target>
</targets>
<targetConfigs>
<targetConfig targets="lightning__FlowScreen">
<property name="label" type="String" role="inputOnly" label="Field label" default="Quantity"/>
<property name="quantity" type="Integer" label="Quantity"/>
</targetConfig>
</targetConfigs>
</LightningComponentBundle>Read it from the top:
apiVersionsets the API version the component runs under.isExposedmakes the bundle visible to builders.masterLabelis the name shown in Flow Builder's component list. Without it, Flow Builder shows the component's API name.- The
<target>element addslightning__FlowScreento the places the component is available. <targetConfig targets="lightning__FlowScreen">applies its settings only to that target.
Properties in the target config
Each <property> element becomes a field in the component's configuration panel in Flow Builder. The attributes you will use most often are in this table:
| Attribute | Purpose |
|---|---|
| `name` | Must match an `@api` property in the component's JavaScript class. |
| `type` | The flow data type, such as `String`, `Integer`, `Boolean`, or `Date`. |
| `label` | The text shown for the property in Flow Builder. |
| `default` | The starting value if the flow author sets nothing. |
| `role` | Restricts the direction: `inputOnly` or `outputOnly`. Leave it out for both. |
In the example, label is inputOnly. The flow can set it, but the component can't send a new value back. The quantity property has no role, so the flow can pass a value in and read the value the component returns.
The next chapter covers properties and data types in detail. For now, remember that a property listed here must have a matching @api property in the JavaScript class, or the flow value has nowhere to go.
Common errors
- The component is missing from Flow Builder. Check that
isExposedistrueand that the target is spelled exactlylightning__FlowScreen, with two underscores. Then confirm the deployment succeeded. - The property shows up, but the value never arrives. The
namein meta.xml does not match the@apiproperty name. Names are case sensitive. - Deployment fails on a property. The
typevalue may not be a supported flow type, or a required attribute may be missing. - Changes don't appear. After you redeploy, refresh Flow Builder, and reopen the flow. Builder caches component metadata.
Where this fits
The sequence below shows how a meta.xml file leads to a component on a flow screen.
Exercise
A developer deploys a component with isExposed set to true and a quantity property in targetConfig. The component does not appear in the Flow Builder screen component list. The <target> element reads lightning_FlowScreen. What is wrong, and how do you fix it?
Show answer
The target name has a single underscore. The correct value is lightning__FlowScreen, with two underscores. Change the <target> element, redeploy, and refresh Flow Builder.
Exercise
You want a title property that the flow author can set but the component can never change. Which attribute and value do you add to the <property> element?
Show answer
Add role="inputOnly", for example <property name="title" type="String" role="inputOnly"/>.