2

I implemented the getPicklistValues method and was able to retrieve the picklist values from a custom object, but when I created a managed package with it the values are not being retrieved.

I created a test managed package with minimal functionality to review this behaviour and found that the issue is happening too.

Here's the simple code I implemented for said package. There is a custom object called Custom_Test_Object__c with 2 picklist values (Test_controlling_value__c and Test_PIcklist_values__c) with one controlling the other. There's also a recordType created so the getPicklistValues method can work:

picklistValuesComponent.html

<template>
    <lightning-combobox 
        class="comboboxOver"
        label="Choose option"
        name="comboGroup"
        onchange={handleReasonChange} 
        options={reasonTypeOptions} 
        value={reasonType}>
    </lightning-combobox>
</template>

picklistValuesComponent.js

    import { LightningElement, wire, track } from 'lwc';
    import { getPicklistValuesByRecordType } from 'lightning/uiObjectInfoApi';
    import { getObjectInfo } from 'lightning/uiObjectInfoApi';

    import FeedbackObject from '@salesforce/schema/Custom_Test_Object__c';

    export default class PicklistValuesComponent extends LightningElement {
    @track reasonTypeOptions = [];
    @track reasonType;
    @track controlValues;
    @track selectedValue;
    
    totalDependentValues = [];

    // Account object info
    @wire(getObjectInfo, { objectApiName: FeedbackObject  })
    objectInfo;

    // Picklist values based on record type
    @wire(getPicklistValuesByRecordType, { objectApiName: FeedbackObject, recordTypeId: '$objectInfo.data.defaultRecordTypeId'})
    reasonPicklistValues({error, data}) {
        if (data) {
            this.controlValues = data.picklistFieldValues.Test_PIcklist_values__c.controllerValues;
            // Unlike Reason dependent Field Picklist values
            this.totalDependentValues = data.picklistFieldValues.Test_PIcklist_values__c.values;

            this.refreshValuesByLikeOrDislike();
        } else if (error) {
            this.error = JSON.stringify(error);
        }
    }

    refreshValuesByLikeOrDislike() {
        let initialOptions = [];
        
        // Set default value
        initialOptions.push({
            label: '-- Select reason --',
            value: 'None'
        });


        this.totalDependentValues.forEach(key => {
            initialOptions.push({
                label : key.label,
                value: key.value
            })
        });
        
        this.reasonTypeOptions = initialOptions;
        this.reasonType = initialOptions[0] ? initialOptions[0].value : '';
    }

    handleReasonChange(event) {
        const selectedOption = event.detail.value;
        this.reasonType = selectedOption;
    }
}

picklistValuesComponent.js-meta.xml

<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>47.0</apiVersion>
<isExposed>true</isExposed>
<masterLabel>Test picklist values lwc component</masterLabel>
<description>Lets you test picklist values.</description>
<targets>
    <target>lightning__RecordPage</target>
    <target>lightningCommunity__Page</target>
    <target>lightningCommunity__Default</target>
</targets>
</LightningComponentBundle>

Any ideas why this is happening?

1
  • 1
    I would immediately think it is related to namespace. Have you tried putting the namespace prefix on the object and field names?
    – Phil W
    Mar 19, 2020 at 22:08

1 Answer 1

0

Like Phil W mentioned I was missing the prefix in the field, so instead of:

Test_PIcklist_values__c I should refer them as mynamespace__Test_PIcklist_values__c

Thank you!

You must log in to answer this question.

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