UI Record API is used for fetching, creating, updating and deleting the particular record without using the SalesForce Apex Class. These APIs are:
- Get Record
- Get Field Value
- Create Record
- Update Record
- Delete Record
Below is the sample code of the js controller of LWC for getting the particular record by record ID:
import { LightningElement, api, wire } from 'lwc';
import { getRecord } from 'lightning/uiRecordApi'; //Import getRecord function of the uiRecordApi
export default class GetRecord extends LightningElement {
@api recordId; // This property store the ID of particular record
@wire(getRecord, { recordId: '$recordId', layoutTypes: ['Compact', 'Full'], modes: ['View', 'Edit', 'Create'] })
viewRecord({ data, error }) {
if (data) {
console.log('Record Data===', data); // This data contains the Record info of particular record
}
if (error) {
console.log('error===' + error);
}
}
}