Documentation Index
Fetch the complete documentation index at: https://mintlify.com/trailheadapps/lwc-recipes/llms.txt
Use this file to discover all available pages before exploring further.
lightning-record-form is the simplest way to create, edit, or view a record using Lightning Data Service. It automatically generates the form layout based on the object’s metadata and handles data loading, saving, and validation.
Usage
Static Field Definition
Import field schema references for type safety and IDE support:Dynamic Field Definition
Specify fields as strings for more flexible runtime configuration:Attributes
| Attribute | Type | Required | Description |
|---|---|---|---|
object-api-name | String | Yes | API name of the object (e.g., ‘Contact’, ‘Account’) |
record-id | String | No | ID of the record to load. Omit to create a new record |
fields | String[] or FieldId[] | No | Array of field API names or field schema references |
layout-type | String | No | Layout to use: ‘Full’ (default) or ‘Compact’ |
mode | String | No | Form mode: ‘view’, ‘edit’, or ‘readonly’ |
columns | Number | No | Number of columns (1 or 2, default is 2) |
record-type-id | String | No | Record type ID for record creation |
Features
- Automatic Layout: Generates form layout based on object metadata
- Built-in Validation: Handles field-level and record-level validation
- Save/Cancel: Includes save and cancel buttons automatically
- Lightning Data Service: Uses LDS for caching and offline support
- Responsive: Adapts to different screen sizes
Related Components
- lightning-record-edit-form - For custom edit layouts
- lightning-record-view-form - For custom view layouts
- createRecord - For programmatic record creation
