Sub topic 3
Controlling Navigation in Screen Flow Components
Assume you know LWC classes, @api properties, custom events, and basic screen flows. A screen component receives the flow’s availableActions property. It lists navigation actions allowed on the current screen.
Next, Back, Pause, and Finish
Dispatch only an event whose action is available. This prevents errors when a flow starts or ends at a screen.
import { LightningElement, api } from 'lwc';
import {
FlowNavigationNextEvent,
FlowNavigationBackEvent,
FlowNavigationPauseEvent,
FlowNavigationFinishEvent
} from 'lightning/flowSupport';
export default class StepButtons extends LightningElement {
@api availableActions = [];
go(action, EventType) {
if (this.availableActions.includes(action)) {
this.dispatchEvent(new EventType());
}
}
handleNext() {
this.go('NEXT', FlowNavigationNextEvent);
}
handleBack() {
this.go('BACK', FlowNavigationBackEvent);
}
handlePause() {
this.go('PAUSE', FlowNavigationPauseEvent);
}
handleFinish() {
this.go('FINISH', FlowNavigationFinishEvent);
}
}A component can also expose validate(). Flow calls it before navigation and blocks the action when it returns { isValid: false }.
Test and debug in Flow Builder
Use Flow Builder’s Debug feature with representative input values. Confirm that:
- The component appears under Custom.
- Inputs are assigned to the expected flow variables.
- Outputs are available to later elements.
- validation blocks invalid input.
- navigation works at the first, middle, and final screens.
Inspect browser errors and add temporary console.log statements for availableActions and changed values. Remove diagnostic logging before deployment.
Reusable and specialized properties
Generic sObject properties let one component work with different record types:
<propertyType name="T" extends="SObject" label="Object type"/>
<property name="records" type="{T[]}" label="Records"/>
<property name="selectedRecord" type="{T}" role="outputOnly"/>Use Apex-defined types when a flow needs a structured class returned by Apex. Keep the Apex class serializable and expose only fields the component needs.
Common pitfalls
Do not mutate a flow input as if it were local state. Treat incoming values as read-only and dispatch a FlowAttributeChangeEvent for outputs. Keep navigation separate from validation, and check availableActions before every navigation event.
A configurationEditor custom property editor can provide a richer setup experience in Flow Builder when standard metadata properties are insufficient. For the opposite direction, an LWC can embed a flow with lightning-flow and call startFlow() with the flow API name and input variables.
Exercise
Why should a component check availableActions before dispatching FlowNavigationFinishEvent?
Show answer
FINISH may not be allowed on the current screen, so the check prevents an unsupported navigation request.