[SalesForce] TypeError: Cannot read properties of undefined (reading ‘values’)

I'm trying to setup a search filter for opportunity stage field through lightning combo box but however getting an error "cannot read properties of undefined while loading the component"

<lightning-combobox
            name="progress"
            label="Opportunity Stage"
            value={value}
            options={stagepicklistValues.data.values}
            onchange={handleChange} >
 </lightning-combobox>

Client Side Controller

import { LightningElement, api, wire, track} from 'lwc';
import { getObjectInfo } from 'lightning/uiObjectInfoApi';
import { getPicklistValues } from 'lightning/uiObjectInfoApi';
import OPPORTUNITY_OBJECT from '@salesforce/schema/Opportunity';
import STAGE_NAME from '@salesforce/schema/Opportunity.StageName';

export default class Accounts extends LightningElement {
@api recordId;
value='';
@wire(getObjectInfo, { objectApiName: OPPORTUNITY_OBJECT })
opportunityMetadata;

@wire(getPicklistValues,
    {
        recordTypeId: '$opportunityMetadata.data.defaultRecordTypeId',
        fieldApiName: STAGE_NAME
    }
)
stagepicklistValues;

Best Answer

1.- what is undefined? there is surely more information as to what variable is undefined.

2.- naming a property value is generally speaking a bad practice. please do not do that.

3.- consider wiring your property to a function instead and add some error handling Ex:

@wire(getSomething)
    wiredFunctionName({ error, data }) {
        if (data) {
           //do something
        } else if (error) {
            //catch error
        }
    }

once you have refactored your code, you should be able to either provide a more detailed error and/or solve it yourself =)

Related Topic