OpportunityLineItem doesn't support getPicklistValues in lwc

Telegram logo Join our Telegram Channel

OpportunityLineItem does not support getPicklistValues in Lightning Web Components #lwc
Image result for lightning web components

As per the documentation, recordTypeId  is required for getPicklistValues method in lighting uiObjectInfoApi. But there are some objects in salesforce which don't support record type, like OpportunityLineItem. So I tried passing null, blank values as recordTypeId  , but it doesn't work.


The below code doesn't work.

import { LightningElement, wire } from 'lwc';
import { getPicklistValues } from 'lightning/uiObjectInfoApi';
import SUB_TYPE from '@salesforce/schema/OpportunityLineItem.SBQQ__SubscriptionType__c';

export default class LwcGetpicklistDemo extends LightningElement {
    @wire(getPicklistValues, { recordTypeId: undefined, fieldApiName: SUB_TYPE })
    propertyOrFunction;
}

So I have done the workaround for it by using the apex aura enabled method as below.

Here is the Apex Code
@AuraEnabled(cacheable=true)
public static List<SelectOption> getOppItemPickListValues(String fieldApiName){
    List<SelectOption> pickListValuesList= new List<SelectOption>();
    if(string.isNotBlank(fieldApiName)){
        Map<String, Schema.SObjectField> fieldsMap= OpportunityLineItem.getSobjectType().getDescribe().fields.getMap();
        List<Schema.PicklistEntry> ple = fieldsMap.get(fieldApiName).getDescribe().getPicklistValues();
        for(Schema.PicklistEntry pickListVal : ple){
            pickListValuesList.add(new SelectOption(pickListVal.getValue(),pickListVal.getLabel()));
        }
    }
    return pickListValuesList;
}

Here is the sample JS code.
import { LightningElement, wire } from 'lwc';
import SUB_TYPE from '@salesforce/schema/OpportunityLineItem.SBQQ__SubscriptionType__c';
import getOppItemPickListValues from '@salesforce/apex/DirectSalesCompController.getOppItemPickListValues';

export default class LwcGetpicklistDemo extends LightningElement {
    @wire(getOppItemPickListValues, {
        fieldApiName: SUB_TYPE.fieldApiName
    })
    typePicklistValues;
}
 Here is the sample HTML code.
<template if:true={typePicklistValues.data}>
    <lightning-combobox label="Subscription Type" value={dropPipeJSLProduct.SBQQ__SubscriptionType__c}
        placeholder="-Select-" options={typePicklistValues.data}
        onchange={handleSubscriptionType}></lightning-combobox>
</template>
This is just a workaround and not a standard solution, lets wait for the salesforce team to update with the standard solution for the same.
No comments :
Post a Comment

Hi there, comments on this site are moderated, you might need to wait until your comment is published. Spam and promotions will be deleted. Sorry for the inconvenience but we have moderated the comments for the safety of this website users. If you have any concern, or if you are not able to comment for some reason, email us at rahul@forcetrails.com