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.
- <lightning-record-view-form /> - used to fetch a form in read-only mode
- <lightning-record-edit-form /> - used to create or update a single record
- <lightning-record-form /> - used to fetch, create, update a single record
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!