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.
To access raw record data or create a form that needs more customization than the lightning-record-*-form
components allow, use Lightning Data Service wire adapters and functions, such as those from the lightning/ui*Api
module.
Lightining : recordForm
import { LightningElement ,api} from 'lwc';
import Name from '@salesforce/schema/Account.Name';
import Phone from '@salesforce/schema/Account.Phone';
import Rating from '@salesforce/schema/Account.Rating';
import Revenue from '@salesforce/schema/Account.AnnualRevenue';
import Industry from '@salesforce/schema/Account.Industry';
export default class LightningRecordForm extends LightningElement {
@api recordId;
@api objectApiName;
fields = [Name, Revenue, Industry, Phone, Rating];
handleSubmit(event) {
event.preventDefault(); // stop the form from submitting
const fields = event.detail.fields;
fields.LastName = 'My Custom Last Name'; // modify a field
this.template.querySelector('lightning-record-form').submit(fields);
}
}
54.0
True
lightning__HomePage
lightning__AppPage
lightning__RecordPage
Output

Lightning :RecordEdit Form
import { LightningElement ,api,track} from 'lwc';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
export default class LightningRecordEditformInLwc extends LightningElement {
@api records;
@api objectName = 'Account';
handleSubmit(event) {
console.log('onsubmit event recordEditForm' + event.detail.fields);
const evt = new ShowToastEvent({
title: 'Message',
message: 'The record has been created successfully.',
variant: 'success',
mode: 'dismissable'
});
this.dispatchEvent(evt);
this.isModalOpen = false;
}
handleSuccess(event) {
console.log('onsuccess event recordEditForm', event.detail.id);
}
}
54.0
True
lightning__HomePage
lightning__AppPage
Output

Lightining : RecordView Form
import { LightningElement ,api} from 'lwc';
export default class LightningRecordViewFormInLwc extends LightningElement {
@api recordId;
}
54.0
True
lightning__HomePage
lightning__AppPage
lightning__RecordPage
Output :
