0

I am trying to pull in picklist values of a field based on record type. The below works -

@wire(getPicklistValuesByRecordType, { objectApiName: 'Case', recordTypeId: '0123h000000kv04AAA' })
typePicklistValues({ error, data }) {
    if (data) {
        console.log(data.picklistFieldValues.Type.values)
        this.options = data.picklistFieldValues.Type.values;
    }
}

If I replace the ObjectAPIName & recordtype with a variable, it doesn't work -

@wire(getPicklistValuesByRecordType, { objectApiName: '$this.objectName', recordTypeId: '$this.recordTypeId' })
typePicklistValues({ error, data }) {
    if (data) {
        console.log(data.picklistFieldValues.Type.values)
        this.options = data.picklistFieldValues.Type.values;
    }
}

All those variables have the actual values, which I checked already, is there anything that I am doing wrong here?

Sumchans
  • 3,088
  • 6
  • 32
  • 59

1 Answers1

2

You do not include this in reactive wire parameters.

Use

@wire(
    getPicklistValuesByRecordType, 
    { objectApiName: '$objectName', recordTypeId: '$recordTypeId' }
)

to achieve this reactivity.

David Reed
  • 2,522
  • 2
  • 16
  • 16
  • Thanks David, I imported the object this way import CASE_OBJECT from '@salesforce/schema/Case';, not sure how to import the recordtypeId to get the picklist values of that recordtypeid. could you show an example? Here is how my wire adapter is as of now @wire(getPicklistValuesByRecordType, { objectApiName: CASE_OBJECT, recordTypeId: '0123h000000kv04AAA' }), need to change the recordTypeId. – Sumchans Jun 15 '21 at 14:37
  • Seeing this from this link https://github.com/trailheadapps/lwc-recipes/blob/main/force-app/main/default/lwc/wireGetPicklistValuesByRecordType/wireGetPicklistValuesByRecordType.js , should recordtypeId be hardcoded, I cant seem to find an example where a variable is used for the recordTypeId. Please advise. – Sumchans Jun 15 '21 at 16:44
  • Thanks David, I figured it out, was being dumb. Thanks again. – Sumchans Jun 15 '21 at 16:48