Salesforce Interview Questions & Answers Book is now available!

Grab Now

LWC

Difference between LDS tags in LWC

Let's understand the methods in LDS in LWC to write better Lightning Web Components

By Teja, ex-Salesforce engineer · Updated February 9, 2021 · 1 min read

When you want to work with a single record in LWC you don't have to write Apex code or use full blown LDS methods like

We can straight away use LDS based tags. Here are the three tags that are available to us as a part of Lightning Data Service in LWC.

What's that one thing that's common across all three tags?
They can be used only on a single record!

These are very much similar to StandardControllers in Salesforce Classic.

When we want to work with multiple records we need to use Apex and we cannot use LDS based approach.

When to use <lightning-record-view-form /> & <lightning-record-edit-form />

lightning-record-view-form/lightning-record-edit-form is used when we want some granular control over the fields.

An exmaple would be, colour highlightning alternative fields on a record. Here  having granular control over each field is the key.

When to use <lightning-record-form />?

We can use lightning-record-form when there are umpteen no of fields and when am not interested in writing the code to fetch each and every field on to the template file.

Here I will just specify the fields using fields attribute or layout-type attribute and all the fields will be fetched onto the template.

Hope this is helpful!

Learn it by building it

Every course, every code repository, the discussion group and certificates of completion — one subscription.

Keep me in the loop!

Email me when a new episode is published (promise, I will not spam you)

You're signing up to receive emails from Salesforce Casts