getObjectInfo

Use this wire adapter to get metadata about a specific object. The response includes metadata describing the object’s fields, child relationships, record type, and theme.

Syntax 

1import { LightningElement, wire } from "lwc";
2import { getObjectInfo } from "lightning/uiObjectInfoApi";
3import ACCOUNT_OBJECT from "@salesforce/schema/Account";
4
5export default class Example extends LightningElement {
6  @wire(getObjectInfo, { objectApiName: ACCOUNT_OBJECT })
7  propertyOrFunction;
8}

User Interface API Resource 

1GET /ui-api/object-info/{objectApiName}

getObjectInfo uses this User Interface API resource.

Parameters 

Parameter NameTypeDescriptionRequired?
objectApiNameStringThe 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 

Usage 

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

This example returns the record type Ids and the Id that matches the record type name “Special Account”.

1import { LightningElement, api, wire, track } from "lwc";
2import { getObjectInfo } from "lightning/uiObjectInfoApi";
3import ACCOUNT_OBJECT from "@salesforce/schema/Account";
4
5export default class RecordFormWithRecordType extends LightningElement {
6  // Flexipage provides recordId and objectApiName
7  @api recordId;
8  @api objectApiName;
9
10  @track objectInfo;
11
12  @wire(getObjectInfo, { objectApiName: ACCOUNT_OBJECT })
13  objectInfo;
14
15  get recordTypeId() {
16    // Returns a map of record type Ids
17    const rtis = this.objectInfo.data.recordTypeInfos;
18    return Object.keys(rtis).find((rti) => rtis[rti].name === "Special Account");
19  }
20}

See Compare Base Components for a full example.

See Also