Developers can now enhance error handling at run time for Lightning web component on a flow screen. Previously, the input validation error message from the flow appeared only under the component. Now components that manage their own validation can control how and where errors appear without the risk of showing duplicate errors. @api interface can be used to implement the existing validate() method and the new methods setCustomValidity(externalErrorMessage: string) and reportValidity()
Where: This change applies to Lightning Experience and Salesforce Classic (not available in all orgs) in Professional, Enterprise, Performance, Unlimited, and Developer editions. It’s not supported in Classic runtime for flows
Why: Previously, if the component contained an invalid input, the flow displayed an input validation error message below the component at run time. If the component also contained validation logic that displayed an error message, the flow user saw duplicate error messages. Now it can be customized how and where to display the error messages
How: For components that contain validation logic, you can now implement these methods to take control of rendering errors.
- validate()
- setCustomValidity(externalErrorMessage: string)
- reportValidity()
For existing component validation, the same logic that’s contained in the validate() method can be kept. Like before, the flow calls the validate() method when a flow user navigates to the next screen or finishes the flow. The flow calls the new setCustomValidity(externalErrorMessage: string) method when there are input validation errors. When the setCustomValidity(externalErrorMessage: string) method is called, the component stores the input validation error message from the flow, so it can be displayed later. The flow calls the reportValidity() method when it’s time to render any errors that your component is aware of