# What role does lightning/uiObjectInfoApi play in fetching object metadata and picklist values?

**Topic:** LWC · **Difficulty:** Medium · **Tags:** LWC, uiObjectInfoApi, Metadata

Read it on the site: https://www.forcechallenges.com/interview-questions/what-role-does-lightning-uiobjectinfoapi-play-in-fetching-object-metadata-and-picklist-values

## Answer

**Basics:** Instead of hard-coding labels or picklist options, an LWC can ask the platform at runtime. `getObjectInfo` returns the object's labels, fields (with data types, labels, createable and updateable flags), child relationships, record type infos and the `defaultRecordTypeId`. `getPicklistValues` returns the values for one picklist field for a given record type.

**How it works:** Import the adapter and field references from `@salesforce/schema`, then wire. First wire `getObjectInfo` to obtain `defaultRecordTypeId` (or take a record's recordTypeId), then wire `getPicklistValues` with `recordTypeId` and `fieldApiName`. The result contains `values` (each with `label`, `value`) and, for dependent picklists, `controllerValues` and per-value `validFor` indexes.

**Advanced / deep dive:** Responses are filtered by the user's access, so they reflect FLS and record type availability, which is the main advantage over hard-coding or Apex describe. They are cached and shared through LDS, reducing server calls, and wire adapters re-provision when reactive parameters change. For many objects use `getObjectInfos` (plural). `getPicklistValuesByRecordType` returns all picklists for a record type in one call, efficient for forms. Dependent picklists: filter `values` by `validFor.includes(controllerValues[selectedControllerValue])`. For the Master record type (no record types defined) use the id `012000000000000AAA`. These adapters give metadata only, not records; combine with `lightning/uiRecordApi` (`getRecord`, `createRecord`, `updateRecord`) for data. Alternatives: `lightning-record-edit-form` with `lightning-input-field` handles picklists automatically; Apex `Schema.describe` is heavier and not cached the same way; the newer GraphQL wire adapter is another data path. In offline mobile, metadata must be primed or cached.

**Code / config example:**
```javascript
import { LightningElement, wire } from 'lwc';
import { getObjectInfo, getPicklistValues } from 'lightning/uiObjectInfoApi';
import ACCOUNT_OBJECT from '@salesforce/schema/Account';
import INDUSTRY_FIELD from '@salesforce/schema/Account.Industry';

export default class IndustryPicker extends LightningElement {
    options = [];

    @wire(getObjectInfo, { objectApiName: ACCOUNT_OBJECT })
    objectInfo;                                   // objectInfo.data.defaultRecordTypeId

    @wire(getPicklistValues, {
        recordTypeId: '$objectInfo.data.defaultRecordTypeId',  // reactive param
        fieldApiName: INDUSTRY_FIELD
    })
    wiredPicklist({ data, error }) {
        if (data) this.options = data.values.map(v => ({ label: v.label, value: v.value }));
        else if (error) console.error(error);
    }
}
```

**Hidden gotchas & must-remember points:**
- `getPicklistValues` needs both `recordTypeId` and `fieldApiName`; a missing record type id returns nothing.
- Wire results are `undefined` first; guard with `data` checks.
- Use `$` prefix for reactive properties.
- Results honour FLS and record type picklist assignments, so different users can see different values.
- Metadata only; it does not return records.
- Dependent picklists need manual filtering using `controllerValues` and `validFor`.

**Best practice:** Use wire adapters with `@salesforce/schema` imports, and prefer `getPicklistValuesByRecordType` when loading several picklists.

---
Source: ForceChallenges · last updated 2026-11-02
