function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Tyler Tran 94Tyler Tran 94 

getObjectInfos is not working

I have a basic coding about getObjectInfos adapter but it seems not working:
import { LightningElement, wire } from 'lwc';
import { getObjectInfos } from 'lightning/uiObjectInfoApi';
import ACCOUNT_OBJECT from '@salesforce/schema/Account';
import OPPORTUNITY_OBJECT from '@salesforce/schema/Opportunity';


export default class GetObjectInfosLwc extends LightningElement {
    @wire(getObjectInfos, {objectApiName:[ACCOUNT_OBJECT, OPPORTUNITY_OBJECT]})
    objectInfosHandler({data, error}) {
        if(data) {
            console.log("Get Multiple " + data)
        }
        if(error) {
            console.error(error)
        }
    }
}
and here is the Browser Console log:
beaconLib.BeaconLibrary.js:37 {InstrumentationResult :  ( RECEIVED = 14 , SUCCESS -> LOG = 14 , Topic = AILTN )  , TracingResponse : ( AsyncResults ) , TelemetryResponse : ( AsyncResults ): {…}}
As you can see, it doesn't print the list of metadata (for Account and Opportunity). I need some help!
Thank you so much.




 
Best Answer chosen by Tyler Tran 94
Surya GSurya G
Hi Tyler,

when requesting for multiple object infos, you should use 'objectApiNames'
@wire(getObjectInfos, {objectApiNames:[ACCOUNT_OBJECT, OPPORTUNITY_OBJECT]})
It will work . Also i would suggest to use JSON.stringify(data) to print values in console.
console.log("Get Multiple " + JSON.stringify(data))
Thanks
Surya G

 

All Answers

Surya GSurya G
Hi Tyler,

when requesting for multiple object infos, you should use 'objectApiNames'
@wire(getObjectInfos, {objectApiNames:[ACCOUNT_OBJECT, OPPORTUNITY_OBJECT]})
It will work . Also i would suggest to use JSON.stringify(data) to print values in console.
console.log("Get Multiple " + JSON.stringify(data))
Thanks
Surya G

 
This was selected as the best answer
Tyler Tran 94Tyler Tran 94
Hi Surya,
What a critical mistake from me!!!
Thank you for your support, hope you doing well bro.