1

I am trying to use the 'getPicklistValues' in a lightning web component.

The goal is to get the picklist values of a custom field on 'User'. However to use the wire function you have to pass a recordTypeId, this doesn't seem possible, since Users don't have record types assigned to them. I am able to do this custom, but I was wondering if there's an option to do this with the default 'getPicklistValues' function.

Sample code for reference;

import { LightningElement, wire, api } from 'lwc';
import { getRecord } from 'lightning/uiRecordApi';
import { getPicklistValues } from 'lightning/uiObjectInfoApi';
import { getObjectInfo } from 'lightning/uiObjectInfoApi';

import USER_OBJECT from '@salesforce/schema/User';
import CUSTOM_FIELD from '@salesforce/schema/User.Custom_field__c';
import userId from '@salesforce/user/Id';

export default class UserCustomFieldSelect extends LightningElement {
@api uId = userId;

@wire(getObjectInfo, { objectApiName: USER_OBJECT})
objectInfo;

@wire(getPicklistValues, { recordTypeId: '$objectInfo.data.defaultRecordTypeId', fieldApiName: ACTIVE_OFFICE_FIELD})
customPicklistValues;

@wire(getRecord, { recordId: '$uId', fields: [CUSTOM_FIELD]})
user;
}

2 Answers 2

2

You have missed one thing in your code syntax. i.e '$objectInfo.defaultRecordTypeId' will not give the default value but '$objectInfo.data.defaultRecordTypeId' will. You missed using data to get the defaultRecordTypeId.

A sample example to use the default record type for getting picklist value in Lightning web component.

import { getPicklistValues } from 'lightning/uiObjectInfoApi';
import { getObjectInfo } from 'lightning/uiObjectInfoApi';

@track objectInfo;

@wire(getObjectInfo, { objectApiName: CONTACT_OBJECT })
objectInfo;

@wire(getPicklistValues, {
   recordTypeId: '$objectInfo.data.defaultRecordTypeId',
   fieldApiName: GENDER_FIELD
})
genders;

Update:-

On User object, we don't have any master record type. I have confirmed it through below piece of code:-

Schema.DescribeSObjectResult dsr = User.SObjectType.getDescribe();
Schema.RecordTypeInfo defaultRecordType;
for(Schema.RecordTypeInfo rti : dsr.getRecordTypeInfos()) {
    if(rti.isDefaultRecordTypeMapping()) {
        defaultRecordType = rti;
        system.debug(defaultRecordType);
    }
}

This is the reason, you are getting the defaultRecordTypeId as undefined.

3
  • This was indeed missing, however defaultRecordTypeId for the user object still returns 'undefined'
    – Kobe
    Oct 4, 2019 at 9:40
  • 1
    @Kobe Please see the update. Oct 4, 2019 at 11:18
  • Does this mean getPicklistValues is not supported for User fields, since there is no default record type? May 18, 2021 at 0:00
0

@Salesforce_Noobie getPicklistValues is supported for User fields, but you need to send a dummy recordtype id to

import { LightningElement,wire } from 'lwc';
import { getObjectInfo, getPicklistValues } from 'lightning/uiObjectInfoApi';
import USER_OBJECT from '@salesforce/schema/User';
import TESTPICKLIST_FIELD from '@salesforce/schema/User.StateCode';
export default class GetPicklistValuesOfField extends LightningElement {
    value ='';
    @wire(getObjectInfo, { objectApiName: USER_OBJECT })
    userMetadata;
    @wire(getPicklistValues,
        {
            recordTypeId: '012000000000000AAA', 
            fieldApiName: TESTPICKLIST_FIELD
        }
    )
    industryPicklist;
    handleChange(event) {
        this.value = event.detail.value;
    }
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .