Salesforce | UI Record API in LWC

Author - Webner
21.07.2021
|
0 Comments
||

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);
}
}
}

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.

Leave a Reply

Your email address will not be published. Required fields are marked *