Sub topic 1
How Screen Flows Host Lightning Web Components
Prerequisites
Assume you know basic Lightning Web Components, @api properties, custom events, and Flow Builder screen elements. You should also know how to deploy an LWC bundle to Salesforce.
A screen flow pauses at each screen, renders its fields and components, then resumes when the user navigates. An LWC on the screen receives configured values from the flow. It can display those values and report changed values back to the flow.
Exposing a Component to Flow Builder
An LWC is not available in Flow Builder automatically. Its component bundle needs a metadata configuration file ending in .js-meta.xml. Set isExposed to true and add the lightning__FlowScreen target.
<?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>
</LightningComponentBundle>After deployment, Flow Builder lists the component in the screen component list. The target controls where the component can be used. A component with only lightning__FlowScreen is intended for flow screens.
Declaring Input and Output Properties
Declare configurable properties inside a targetConfig for the Flow Screen target. Each property becomes available in the screen's configuration panel. A property without a role can generally act as both input and output. Use inputOnly or outputOnly when you need to restrict its direction.
<targetConfigs>
<targetConfig targets="lightning__FlowScreen">
<property name="label" type="String"
role="inputOnly" label="Field label"/>
<property name="quantity" type="Integer"
label="Quantity"/>
</targetConfig>
</targetConfigs>The declared type must match the kind of flow value you connect. Common types include String, Boolean, Integer, Decimal, and Date.
> Callout note > Treat values supplied by the flow as inputs. Do not assume that changing a JavaScript property alone updates the flow variable.
Receiving Flow Values in Your Component
Expose matching properties with @api. Salesforce assigns configured values when the screen loads and can assign them again when the flow state changes.
import { LightningElement, api } from 'lwc';
export default class QuantityPicker extends LightningElement {
@api label = 'Quantity';
@api quantity;
get displayValue() {
return this.quantity ?? 'No quantity supplied';
}
}Use label and quantity in the template. Keep input handling separate from rendering so the component remains predictable when the flow supplies a new value.
Exercise
Which metadata setting makes an LWC selectable as a component on a Flow Builder screen?
Show answer
Add <target>lightning__FlowScreen</target> and set <isExposed>true</isExposed>.