To work with data and metadata for Salesforce records, The simplest way to work with data is to use the base Lightning components built on LDS and one of them is lightning-record-form.
What is lightning-record-form?
A lightning-record-form component enables you to quickly create forms to add, view, or update a record. Using this component to create record forms is easier than building forms manually with lightning-record-edit-form and lightning-record-view-form.
How it is different from lightning-record-edit-form?
- lightning-record-form does not support client-side validation quite the same as lightning-record-edit-form
- The lightning-record-form component performs client-side validation on record fields only if you interact with them.
- In contrast, the lighting-record-edit-form component flags fields that have incorrect values even if you did not interact with the fields.
Note – For most use cases, lightning-record-form provides a great starting point. It combines and simplifies the functionality of lightning-record-view-form and lightning-record-edit-form.
Capabilities of lightning-record-form
- Create Records
- Edit Records
- View Records
- Read-Only Mode
- Layout Types
- Multi Column Layout
What you cannot do with lightning-record-form?
- Custom Layout for Fields
- Custom Rendering of Record Data
What are the custom events available for lightning-record-form?
- load – The event fired when the record form loads record data.
- error – The event fired when the record form encounters an error.
- success – The event fired when the record form submits successfully.
- cancel – The event fired when the user cancels the form.
What if your org uses record type?
Picklist fields display values according to your record types. You must provide a record type ID using the record-type-id attribute if you have multiple record types on an object and you don’t have a default record type. Otherwise, the default record type ID is used.
Where you can use lightning-record-form?
- Lightning Experience
- Lightning Communities
- Salesforce Mobile App
What are the attributes available for lightning-record-form?
- record-type-id – The ID of the record type, which is required if you created multiple record types but don’t have a default.
- mode – Specifies the interaction and display style for the form. Possible values: view, edit, readonly.
- layout-type -The type of layout to use to display the form fields. Possible values: Compact, Full. When creating a new record, the full layout is displayed, even if you specify a compact layout.
- record-id – The ID of the record to be displayed.
- object-api-name – The API name of the object.It is required.
- columns – Specifies the number of columns for the form.
- fields – List of fields to be displayed.
What are the methods available for lightning-record-form?
- submit – It takes fields attribute of type unknown as argument.It submits the form and it can be accessed globally.
Does lightning-record-form respect field-level security and sharing for you?
Yes,This component takes care of field-level security and sharing for you, so users see only the data that they have access to.
What happens when you mention both fields and layout-type attribute?
If you provide the fields attribute and the layout-type attribute, the fields specified in the fields attribute are loaded before the layout fields.The fields load in the order you list them.
What is default mode of lightning-record-form?
Edit mode is the default mode of this component, so you don’t need to specify the mode when editing records.
What is default layout-type of lightning-record-form?
You also don’t need to specify a layout type because the full layout is used automatically.
Does error are automatically handled?
Yes, errors are automatically handled and displayed. To customize them, use the onerror attribute.