Salesforce Decode
Salesforcedecode
Back to questions
LWCIntermediaterecord-edit-formvalidationforms

Troubleshoot lightning-record-edit-form custom validation timing

Real World Scenario

Custom onsubmit handler runs before field-level validation; invalid records reach Apex causing confusing duplicate error messages.

Expected Answer

• Use onload to register field change handlers for inline validation before submit • reportValidity on native inputs; lightning-input-field exposes validity API • Prevent default on submit when client validation fails • Do not duplicate server validation messages — map Apex errors to fields • Order: client required → format → custom cross-field → server • Test required picklist and lookup validation paths separately • Document validation ownership: LWC vs trigger vs validation rules

Follow-Up Questions & Answers

Click to expand — each follow-up includes a direct, interview-ready answer

Main difference: use case and scale. Use onload to register field change handlers for inline validation before submit. reportValidity on native inputs; lightning-input-field exposes validity API. Pick based on your integration pattern and team capability. Validation layering must be intentional — users hate seeing the same error three times in different wording. Balance speed of delivery with maintainability.

Architect Perspective

Validation layering must be intentional — users hate seeing the same error three times in different wording.