Salesforce | UI Record API in LWC(Lightning Web Component)
UI Record API is used for fetching, creating, updating and deleting the particular record without using the SalesForce Apex Class. These APIs are:
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);
}
}
}
Webner Solutions is a Software Development company focused on developing Insurance Agency Management Systems, Learning Management Systems and Salesforce apps. Contact us at dev@webners.com for your Insurance, eLearning and Salesforce applications.
Originally published at https://blog.webnersolutions.com on July 21, 2021.