getObjectInfos

Use this wire adapter to get metadata for multiple objects. The response includes metadata describing the fields, child relationships, record type, and theme for each object.

Syntax 

1import { LightningElement, wire } from "lwc";
2import { getObjectInfos } from "lightning/uiObjectInfoApi";
3import ACCOUNT_OBJECT from "@salesforce/schema/Account";
4import OPPORTUNITY_OBJECT from "@salesforce/schema/Opportunity";
5
6export default class GetObjectInfosExample extends LightningElement {
7  @wire(getObjectInfos, { objectApiNames: [ACCOUNT_OBJECT, OPPORTUNITY_OBJECT] })
8  propertyOrFunction;
9}

Parameters 

Parameter NameTypeDescriptionRequired?
objectApiNameString[]The API name of a supported object.Yes

Read the data that’s returned by the wire adapter using a property or function.

propertyOrFunction—A private property or function that receives the stream of data from the wire service.

  • If a property is decorated with @wire, the results are returned to the property’s data property or error property.
  • If a function is decorated with @wire, the results are returned in an object with a data property and an error property.

Returns 

Get the object metadata using data.results. The object metadata is returned in the same order they are requested. If a requested object contains an error, the error code and message are returned in data.results[].result. The error object is returned only if the server call fails.

1{
2  "results": [
3    {
4      "result": ObjectInfo1,
5      "statusCode": 200
6    },
7    {
8      "result": ObjectInfo2,
9      "statusCode": 200
10    },
11    {
12      "result": [
13                {
14                    "errorCode": "FORBIDDEN",
15                    "message": "You don't have access to this record. Ask your administrator for help or to request access."
16                }
17        ],
18        "statusCode": 403
19    }
20  ]
21}

Usage 

To get metadata for multiple objects, use getObjectInfos. To work with a single object, use getObjectInfo.

This example returns object info for Account and Opportunity.

1import { LightningElement, wire } from "lwc";
2import { getObjectInfos } from "lightning/uiObjectInfoApi";
3import ACCOUNT_OBJECT from "@salesforce/schema/Account";
4import OPPORTUNITY_OBJECT from "@salesforce/schema/Opportunity";
5
6export default class WireGetObjectInfo extends LightningElement {
7  objectApiNames = [ACCOUNT_OBJECT, OPPORTUNITY_OBJECT];
8
9  @wire(getObjectInfos, { objectApiNames: "$objectApiNames" })
10  objectInfos;
11
12  get objectInfosStr() {
13    return this.objectInfos ? JSON.stringify(this.objectInfos.data, null, 2) : "";
14  }
15}