Q&A on lightning-record-form in Lightning Web Component

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

  1. Create Records
  2. Edit Records
  3. View Records
  4. Read-Only Mode
  5. Layout Types
  6. Multi Column Layout

What you cannot do with lightning-record-form?

  1. Custom Layout for Fields
  2. Custom Rendering of Record Data

What are the custom events available for lightning-record-form?

  1. load – The event fired when the record form loads record data.
  2. error – The event fired when the record form encounters an error.
  3. success – The event fired when the record form submits successfully.
  4. 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?

  1. Lightning Experience
  2. Lightning Communities
  3. Salesforce Mobile App

What are the attributes available for lightning-record-form?

  1. record-type-id – The ID of the record type, which is required if you created multiple record types but don’t have a default.
  2. mode – Specifies the interaction and display style for the form. Possible values: view, edit, readonly.
  3. 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.
  4. record-id – The ID of the record to be displayed.
  5. object-api-name – The API name of the object.It is required.
  6. columns – Specifies the number of columns for the form.
  7. fields – List of fields to be displayed.

What are the methods available for lightning-record-form?

  1. 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.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s