In this blog post we will learn how to use getObjectInfo in Lightning Web Component.
Let us take a simple example to understand the use of getObjectInfo in Lightning Web Component.
objectInfoComp.html
<template>
<p>Object Info Component</p>
</template>
objectInfoComp.js
import { LightningElement,
wire } from 'lwc';
import { getObjectInfo }
from 'lightning/uiObjectInfoApi';
import ACCOUNT_OBJECT from
'@salesforce/schema/Account';
export default class
ObjectInfoComp extends LightningElement {
@wire(getObjectInfo, { objectApiName:
ACCOUNT_OBJECT })
wiredData({data, error}){
if(data){
console.log('Object INFO:', data);
}
if(error){
console.log('Some Error Occured');
}
}
}
objectInfoComp.js-meta.xml
<?xml
version="1.0" encoding="UTF-8"?>
<LightningComponentBundle
xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>50.0</apiVersion>
<isExposed>true</isExposed>
<targets>
<target>lightning__RecordPage</target>
</targets>
</LightningComponentBundle>
Now, Add the component on account record lightning page as shown below,
Open the console and we will be able to see all different information related to the object as shown below.
No comments:
Post a Comment