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
Check this out if you want to understand the purpose of each tag!
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:recordViewForm /> - used to fetch a form in read-only mode
- <lightning:recordEditForm /> - used to create or update a single record
- <lightning:recordForm /> - 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:recordViewForm /> & <lightning:recordEditForm />
lightning:recordViewForm/lightning:recordEditForm 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:recordForm />?
We can use lightning:recordForm 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.