When should you use lightning-record-form versus lightning-record-edit-form for data entry?
Answer
Basics: Both are Lightning Data Service components, so they need no Apex, enforce field-level security, and respect record types and validation rules. The difference is flexibility. record-form generates the whole form from field lists or the page layout. record-edit-form is a container where you place each field yourself.
How it works:
lightning-record-form: setobject-api-name, optionallyrecord-id, then eitherfields={fields}orlayout-type="Compact|Full", andmode(view,edit,readonly). It renders its own Save and Cancel buttons and firesonsuccess,onerror,onsubmit,oncancel.lightning-record-edit-form: setobject-api-nameandrecord-id(omit for create). Addlightning-input-field field-name="..."elements,lightning-messagesfor errors, and your own submit button (type="submit").- Intercept
onsubmit:event.preventDefault()then modifyevent.detail.fieldsand callthis.template.querySelector('lightning-record-edit-form').submit(fields). onsuccessreturnsevent.detail.id.
Advanced / deep dive: record-form is limited: you cannot reorder or insert custom elements between fields, and it has restricted customization of buttons. record-edit-form allows conditional fields (lwc:if), default values, field-by-field styling, multi-column layouts, and custom buttons. is the read-only counterpart. Neither supports saving multiple records or related-object children in one transaction; use Apex for that. They also do not support every field type in every context, so test compound and special fields. Pass to get the correct picklist values for a record type. Both share LDS cache, so other components on the page update after save. Use only inside an edit form; elsewhere use .