Get Picklist Values using LWC

Get Picklist Values using LWC

Get Picklist Values using LWC

We must to use a wire adapter to get the picklist values for a specified field. To use getPicklistValues we should pass the recordTypeId, if our object doesn’t has any record type created, we should set the master Record Type('012000000000000AAA')

JS


import { LightningElement, wire, track } from 'lwc';
import { getPicklistValues } from 'lightning/uiObjectInfoApi'; 
import PIRATE_FIELD from '@salesforce/schema/OpportunityLineItem.Pirate__c'; 

export default class Pirate extends LightningElement {
    masterRecordType = '012000000000000AAA';

    // GET OBJECT INFO
    @wire(
        getPicklistValues, 
        { recordTypeId: '$masterRecordType', fieldApiName: PIRATE_FIELD }
    )
    picklistValues;
}

HTML


<template>
    <lightning-card title="Pirate PicklistValues">
        <template if:true={picklistValues.data}>
           <template for:each={TypePicklistValues.data.values} for:item="item">
              <span key={item.value}>
                {item.label}
              </span>
            </template>
          </template>
    </lightning-card>
</template>
comments powered by Disqus