lwcPicklistWithRecordtype.js
import { LightningElement,wire } from 'lwc';
import { getPicklistValues } from 'lightning/uiObjectInfoApi';
import STAGE from '@salesforce/schema/Opportunity.StageName';
export default class LwcPicklistWithRecordtype extends LightningElement {
@wire(getPicklistValues,
{
recordTypeId: '01228000000XckuAAC',
fieldApiName: STAGE
}
)
stageValues;
}
lwcPicklistWithRecordtype.html
<template>
<div class="slds-box">
<template if:true={stageValues.data}>
<lightning-combobox name="progress" label="Opportunity Stage" value={value}
options={stageValues.data.values} onchange={handleChange}>
</lightning-combobox>
</template>
</div>
</template>
-------------------------------------------------------------------------------------------------
Get picklist values if we don't have recordtypes in Object In Lightning Web Components (LWC)
If object does not have record type's then use the defaultRecordTypeId property, this can be fetch from getRecordUi or getObjectInfo. See below example.
lwcPicklistWithoutRecordtype.js
import { LightningElement,wire } from 'lwc';
import { getPicklistValues } from 'lightning/uiObjectInfoApi';
import LeadSource from '@salesforce/schema/Contact.LeadSource';
import { getObjectInfo } from 'lightning/uiObjectInfoApi';
import CONTACT_OBJECT from '@salesforce/schema/Contact';
export default class LwcPicklistWithoutRecordtypeextends LightningElement {
@wire(getObjectInfo, { objectApiName: CONTACT_OBJECT })
contactInfo;
@wire(getPicklistValues,
{
recordTypeId: '$contactInfo.data.defaultRecordTypeId',
fieldApiName: LeadSource
}
)
leadSourceValues;
}
lwcPicklistWithoutRecordtype.html
<template>
<div class="slds-box">
<template if:true={leadSourceValues.data}>
<lightning-combobox name="progress" label="Lead Source" value={value}
options={leadSourceValues.data.values} onchange={handleChange}>
</lightning-combobox>
</template>
</div>
</template>