0

I have a LWC component where I am fetching picklist values for a SObject field using getPicklistValues wire adapter

Here is sample code in developer org:

@wire(getPicklistValues, { fieldApiName: FIELD_NAME, recordTypeId: '012000000000000AAA' })
wiredActions({ data, error }) {
    if (data) {
        // Set picklist option
    } else if (error) {
        showToastError(this, { message: reduceErrors(error) });
    }
}

It works perfectly in Developer org, but after packaging this is failing with error The requested resource does not exist

After debugging, I found the source code has a different recordType Id in installed package

wiredActions: {
    adapter: uiObjectInfoApi.getPicklistValues,
    dynamic: [],
    method: 1,
    config: function ($cmp) {
        return {
            fieldApiName: FIELD_NAME,
            recordTypeId: '012ao00000077mnAAA' // This is not a valid master record type Id and seems like the reason for wire failure
        };
    }
}

Is it a known salesforce issue and is there a workaround to avoid the issue?

1 Answer 1

2

The recordtype ID changing between your developer org and the installed package environment. Recordtype IDs are unique to each Salesforce org, so a recordtype ID in your developer org will not be the same in another org where the package is installed.

Avoid hardcoding the record type ID, you can fetch the default record type ID dynamically using the getObjectInfo wire adapter.

import { LightningElement, wire, api } from 'lwc';
import { getPicklistValues } from 'lightning/uiObjectInfoApi';
import { getObjectInfo } from 'lightning/uiObjectInfoApi';
import FIELD_NAME from '@salesforce/schema/YourObject.YourField';
import YOUR_OBJECT from '@salesforce/schema/YourObject';

export default class YourLWCComponent extends LightningElement {
        @api objectApiName = YOUR_OBJECT;

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

        @wire(getPicklistValues, {recordTypeId: '$objectInfo.data.defaultRecordTypeId', fieldApiName: FIELD_NAME })
                wiredActions({ data, error }) {
                if (data) {
                        // Set picklist option
                } else if (error) {
                        // Handle error
                }
        }
}

Reference:

You must log in to answer this question.

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