Create and Start a Flow in a Custom Lightning Web Component
Create and start a screen flow from any Lightning web component to yours.
lightning-flow
represents a flow interview in Lightning runtime. To create a flow in your component, set the lightning-flow
component’s flow-api-name
attribute to the API name of the flow that you want to use. To use this component, build a flow with the Salesforce Flow Builder first. The component includes the navigation buttons Back, Next, Pause, and Finish.
If your flow has custom Lightning web components or Aura components, then you can’t use lightning-flow
on Experience Cloud sites that use Lightning Web Runtime.
This example creates and starts the Survey Customers flow.
You can provide initial inputs for the interview by setting the flow-input-variables
attribute to an array of input values.
This example creates and starts an interview by passing in initial values for the flow. It handles a change in the interview using the onstatuschange
event handler.
The lightning-flow
component only supports active flows for the flow-api-name
attribute.
The onstatuschange
event returns these parameters.
If your flow has custom Lightning web components or Aura components, then you can’t uselightning-flow
on Experience Cloud sites that use Lightning Web Runtime.
Parameter | Type | Description |
---|---|---|
activeStages | Object[] | The current value of the $Flow.ActiveStages variable in the flow. Available in API version 42.0 and later. |
currentStage | Object | The current value of $Flow.CurrentStage variable in the flow. Available in API version 42.0 and later. |
flowTitle | String | The flow’s label. |
helpText | String | The help text for the current screen. Available in API version 42.0 and later. |
guid | String | The interview’s GUID. Available in API version 42.0 and later. |
outputVariables | Object[] | The current values for the flow’s output variables. |
status | String | The status of the interview. Valid statuses for a flow interview are:
|
Each flow component includes the navigation buttons Back, Next, Pause, and Finish, which navigate within the flow. By default, when the flow finishes, the component reloads the first screen for a new interview. To customize what happens when the flow finishes, add an event handler for the onstatuschange
action when status is FINISHED.