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.

ParameterTypeDescription
activeStagesObject[]The current value of the $Flow.ActiveStages variable in the flow. Available in API version 42.0 and later.
currentStageObjectThe current value of $Flow.CurrentStage variable in the flow. Available in API version 42.0 and later.
flowTitleStringThe flow’s label.
helpTextStringThe help text for the current screen. Available in API version 42.0 and later.
guidStringThe interview’s GUID. Available in API version 42.0 and later.
outputVariablesObject[]The current values for the flow’s output variables.
statusStringThe status of the interview. Valid statuses for a flow interview are:
  • STARTED: The interview successfully started.
  • PAUSED: The interview successfully paused.
  • FINISHED: The interview for a flow with screens finished.
  • FINISHED_SCREEN: The interview for a flow without screens finished, and the component displayed a default screen with this message: Your flow finished.
  • ERROR: Something went wrong and the interview failed.

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.