What is Lightning Data Service



 Lightning Data Service (LDS) using LWC

Lightning Data service: Lightning Data service is a centralized data caching framework which is used to load, save, create, and delete a record without server – side apex code.

  • Lightning Data Service maintains consistent, up-to-date data across multiple components and clients throughout the app lifecycle. If several components use Lightning Data Service to work with a record, and one of them updates the record, the other components automatically reflect that update.

Below are 3 base Lightning components built on Lightning Data Service (LDS)

  1. lightning-record-form
  2. lightning-record-view-form
  3. lightning-record-edit-form

lightning-record-form

  • Use the lightning-record-form component 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 or lightning-record-view-form.
  • We can use the lightning-record-form component 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 or lightning-record-view-form. The lightning-record-form component provides these helpful features:
  • Switches between view and edit modes automatically when the user begins editing a field in a view form
  • Provides Cancel and Save buttons automatically in edit forms
  • Uses the object’s default record layout with support for multiple columns
  • Loads all fields in the object’s compact or full layout, or only the fields you specify
  • However, lightning-record-form is less customizable. To customize the form layout or provide custom rendering of record data, use lightning-record-edit-form (add or update a record) and lightning-record-view-form (view a record).
  • The object-api-name attribute is always required, and the record-id is required only when you’re editing or viewing a record.
  • lightning-record-form implements Lightning Data Service and doesn’t require additional Apex controllers to create or edit record data. It also takes care of field-level security and sharing for you, so users see only the data that they have access to.

Limitations:
  • Does not support client side validation.
  • All standard objects are not supported like task, event.
lightning-record-view-form
  • Use the lightning-record-view-form component to create a form that displays Salesforce record data for specified fields associated with that record. The fields are rendered with their labels and current values as read-only.
  • You can customize the form layout or provide custom rendering of record data. If you don’t require customizations, use lightning-record-form instead.
  • To specify read-only fields, use lightning-output-field components inside lightning-record-view-form.
  • lightning-record-view-form requires a record ID to display the fields on the record. It doesn’t require additional Apex controllers or Lightning Data Service to display record data. This component also takes care of field-level security and sharing for you, so users see only the data they have access to.
    Example: 
recordViewForm.html

recordViewForm.js

recordViewForm.js-meta.xml

Output:


lightning-record-edit-form

Use the lightning-record-edit-form component to create a form that’s used to add a Salesforce record or update fields in an existing record on an object. The component displays fields with their labels and the current values, and enables you to edit their values.

lightning-record-edit-form supports the following features.
  • Editing a record’s specified fields, given the record ID.
  • Creating a record using specified fields.
  • Customizing the form layout
  • Custom rendering of record data
  • If you don’t require customizations, use lightning-record-form instead.
To specify editable fields, use lightning-input-field components inside lightning-record-edit-form component. See the Editing a Record section.

To display record fields as read-only in lightning-record-edit-form, use lightning-output-field components to specify those fields. You can also use HTML and other display components such as lightning-formatted-name to display non-editable content.

To display all fields as read-only, use the lightning-record-form component with mode="readonly" or the lightning-record-view-form component instead of lightning-record-edit-form

    Example: 
recordEditForm.html

recordEditForm.js

recordEditForm.js-meta.xml

Output
    



Video





Thankyou
SFDC TELUGU.





Post a Comment

0 Comments