Sub topic 3
Declaring input and output properties in meta.xml
This chapter assumes you can write a basic LWC with @api properties, and that you know what flow variables and screen elements are. It covers the metadata side of the contract between a flow and a component: how you declare which values flow in, which flow out, and what data types they use.
Why the meta.xml file matters
A component's JavaScript decides how it behaves. The js-meta.xml file decides what Flow Builder can see. Flow Builder never reads your JavaScript. It reads the targetConfig for lightning__FlowScreen and builds the component's configuration panel from it.
This has three consequences:
- An
@apiproperty that has no matching<property>element is invisible to the flow author. - A
<property>element with no matching@apiproperty shows up in Flow Builder but does nothing at runtime. - The
typeyou declare in XML is what Flow Builder uses to filter which variables and resources the author can pick.
The structure of a flow target configuration
Each property is declared inside a targetConfig element that applies to the lightning__FlowScreen target. The target must also be listed in <targets>, and isExposed must be true.
<?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>The name attribute of each property must match the @api property name in the JavaScript class exactly, including case.
Property attributes
| Attribute | Purpose | Notes |
|---|---|---|
| `name` | Links the XML entry to the `@api` property | Required. Case-sensitive. |
| `type` | Data type the flow uses | Required. See the type list below. |
| `label` | Text shown in Flow Builder | Optional. Defaults to the name. |
| `description` | Help text shown beside the field | Optional but useful. |
| `default` | Value used if the author supplies none | Applies to input. |
| `role` | Restricts direction | `inputOnly` or `outputOnly`. |
| `required` | Makes the author supply a value | Applies to input. |
Input, output, or both
If you leave out role, the property is both an input and an output. The flow author can set an initial value, and the component can send a new value back. This suits a value the user edits, such as quantity above.
role="inputOnly"means the flow can set the value, but the component can't return a new one. Use it for labels, configuration flags, and any value the component only displays.role="outputOnly"means the component produces the value and the author can't set it. Use it for results the component computes, such as the record a user selected.
Choosing a role is more than documentation. It controls what Flow Builder shows. An inputOnly property appears in the component's configuration panel. An outputOnly property does not appear there at all. It becomes available later as an output of the component, under the component's name, when the author builds later elements.
In the example, label is inputOnly. The author types "Quantity" or another label, and the component never changes it. quantity has no role, so the author can preload a value and read the edited result afterward.
Supported data types
The type attribute accepts these values for flow screen components:
| Type | Flow data type | Typical JavaScript value |
|---|---|---|
| `String` | Text | string |
| `Integer` | Number with zero decimals | number |
| `Boolean` | Boolean | boolean |
| `Date` | Date | string in ISO format |
| `DateTime` | Date/Time | string in ISO format |
| `{T}` | A generic sObject | object |
| `{T[]}` | A collection of a generic sObject | array |
| `@salesforce/schema/Account` style or `apex://Namespace.Class` | A specific sObject or Apex-defined type | object |
Two details cause frequent confusion:
- Flow has a single Number type with a number of decimal places, and
Integermaps to the zero-decimal case. If you need decimals, check the current Salesforce documentation for the type your API version supports, and test with a decimal flow variable before relying on it. - Dates arrive as strings. Parse them in JavaScript before doing arithmetic, and send back an ISO-formatted string.
Generic sObject types and Apex-defined types get their own chapters. Here you only need to recognize them.
Matching the JavaScript
For every property declared in XML, you need a public property in the class. Here is the component that goes with the metadata above.
import { LightningElement, api } from 'lwc';
import { FlowAttributeChangeEvent } from 'lightning/flowSupport';
export default class QuantityPicker extends LightningElement {
@api label = 'Quantity';
@api quantity;
handleChange(event) {
const parsed = parseInt(event.detail.value, 10);
this.quantity = Number.isNaN(parsed) ? undefined : parsed;
this.dispatchEvent(new FlowAttributeChangeEvent('quantity', this.quantity));
}
}The names label and quantity in the class match the name attributes. The next chapters cover how values arrive and how FlowAttributeChangeEvent sends them back. For now, notice that only quantity is reported, because only quantity is allowed to flow out.
Note the default value in two places. The class sets label = 'Quantity' and the XML sets default="Quantity". The XML default is what the flow author sees in the builder and what the flow passes in. The class default only applies if the component is used somewhere that doesn't supply a value, so keeping both in agreement avoids surprises.
How values travel
Required properties and defaults
Add required="true" to an input the author must supply. Flow Builder then refuses to save the flow until the author provides a value. This catches configuration mistakes at design time, before any user sees the screen.
Be careful with default. It is a string in XML, and Flow Builder interprets it for the declared type. A default="5" on an Integer is fine. A default on a Boolean should be true or false.
<targetConfig targets="lightning__FlowScreen">
<property name="minimum" type="Integer" role="inputOnly" label="Minimum" default="1" required="true"/>
<property name="allowZero" type="Boolean" role="inputOnly" label="Allow zero" default="false"/>
<property name="result" type="Integer" role="outputOnly" label="Result"/>
</targetConfig>Generic sObject properties
A propertyType element declares a placeholder type. The flow author picks the real object type, and your properties use the placeholder in braces.
<targetConfig targets="lightning__FlowScreen">
<propertyType name="T" extends="SObject" label="Object type" description="The object type of the records"/>
<property name="records" type="{T[]}" label="Records" description="Records to display"/>
<property name="selectedRecord" type="{T}" label="Selected record" role="outputOnly"/>
</targetConfig>{T[]} is a collection of the chosen object and {T} is a single record. One component can then work with accounts in one flow and cases in another. A later chapter covers this in depth.
Common errors
- The property doesn't appear in Flow Builder. Check that
isExposedistrue, that the target is listed, and that thetargetConfighastargets="lightning__FlowScreen". Then redeploy and refresh the builder. - The deployment fails with a name error. The
nameattribute must refer to an@apiproperty. A typo is the usual cause. - Changing the type later breaks existing flows. A flow that already uses the component stores the data type. Changing
IntegertoStringcan invalidate those flows. Add a new property and retire the old one instead. - An
outputOnlyproperty is set but never reaches the flow. Declaring it in XML is not enough. The component must dispatchFlowAttributeChangeEventfor it. - A value shows as empty on the first screen. The flow passes inputs after the component is created, so the constructor sees
undefined. Read inputs inconnectedCallbackor in getters, not the constructor.
Summary of decisions
- Start from what the flow author needs to configure. Those become
inputOnlyproperties. - Add
outputOnlyproperties for the results the flow uses afterward. - Leave
roleoff only for values the user edits and the flow needs to preload. - Give every property a clear
labelanddescription, because the author never sees your code. - Set
requiredwhere a missing value makes the component useless.
Exercise
A component shows a heading, lets the user choose a date, and returns the chosen date. Write the three property elements for heading, chosenDate, and minimumDate (the earliest allowed date, set by the flow author). Give each the correct type and role, and say which ones the component must report with FlowAttributeChangeEvent.
Show answer
<property name="heading" type="String" role="inputOnly" label="Heading"/> <property name="minimumDate" type="Date" role="inputOnly" label="Earliest allowed date"/> <property name="chosenDate" type="Date" role="outputOnly" label="Chosen date"/> The heading and the minimum date are configuration, so they are inputOnly. The chosen date is produced by the component, so it is outputOnly. Only chosenDate needs a FlowAttributeChangeEvent, dispatched as new FlowAttributeChangeEvent('chosenDate', value) each time the user picks a date. If the flow should preload a date, remove the role from chosenDate so it is both input and output.
Exercise
You renamed an @api property from qty to quantity but forgot to update the meta.xml. What do you observe, and how do you fix it?
Show answer
Flow Builder still shows the old qty property, which does nothing at runtime because the class no longer has it, and quantity is not configurable by the author. Update the name attribute in the property element to quantity, redeploy, and check existing flows that referenced qty, since they need to be re-mapped to the new property.