How to get picklist values in lwc without Apex code?

This wire adapter fetches picklist values for a specific field on an object, allowing you to dynamically populate dropdowns and other selection elements.


import { LightningElement, wire } from 'lwc';
import { getPicklistValues } from 'lightning/uiObjectInfoApi';
import INDUSTRY_FIELD from '@salesforce/schema/Account.Industry';

export default class IndustryPicklist extends LightningElement {
@wire(getPicklistValues, { fieldApiName: INDUSTRY_FIELD })
picklistValues;

get options() {
return this.picklistValues.data ? this.picklistValues.data.values : [];
}
}

Use this for picklist with record type
import ACCOUNT_OBJ from ‘@salesforce/schema/Account’;

@api recordTypeId;

@wire(getPicklistValuesByRecordType, { objectApiName: ACCOUNT_OBJ, recordTypeId: ‘$recordTypeId’ })

html file –

<template> <lightning-combobox options={options} placeholder="Select an Industry"></lightning-combobox> </template>

Share your love:

Leave a Reply

Your email address will not be published. Required fields are marked *