0

Usecase is to get the picklist values according to the record type of the Record.

selectedCaseId;
caseRecordTypeId;
wiredCaseRecordTypeId;

@wire(getRecord, {
    recordId: "$selectedCaseId",
    fields: "RecordTypeId"
})
recordData(wireResult) {
    this.wiredCaseRecordTypeId = wireResult;
    const { data, error } = wireResult;
    
    if (data) {
        this.caseRecordTypeId = data.recordTypeId;
        // refreshApex(this.wiredCategory);
        console.log('caseRecordTypeId - ', this.caseRecordTypeId);
    }
    if(error) {
        this.caseRecordTypeId = undefined;
        console.error(error)
    }
}

wiredCategory;

@wire(getPicklistValues, {
    recordTypeId: "$caseRecordTypeId",
    fieldApiName: Category
})
typeInfo1(wireResult) {
    const { data, error } = wireResult;
    this.wiredCategory = wireResult;

    if (data) {
        this.categoryOptions = data.values;
        this.dispatchEventOnCaseClick();
    }
    if(error) {
        console.error(error)
    }
}

Above are the two wired methods-

  • First wired method is used to get the record type id of a particular case.
  • Second wired method is used to get the picklist value belonging to that record type.

Whenever a case is clicked from the list we call the wired method again via refreshApex.

handleCaseClick(event, caseId) {
    if (event) {
        caseId = event.currentTarget.dataset.caseId;
    }

    this.selectedCaseId = caseId;
    refreshApex(this.wiredCaseRecordTypeId);
}

It is working on any first case click, afterwards, it throws the following error - enter image description here

1 Answer 1

1

EDIT:

Also, this is wrong:

@wire(getRecord, {
  recordId: "$selectedCaseId",
  fields: "RecordTypeId"
})

This should be

@wire(getRecord, {
  recordId: "$selectedCaseId",
  fields: ["Case.RecordTypeId"]
})

You have the fieldApiName incorrect. You need to specify it as Object.Field (a fully qualified name).

You have this:

@wire(getPicklistValues, {
  recordTypeId: "$caseRecordTypeId",
  fieldApiName: Category
})

You should specify the field in the imports area:

import CATEGORY_FIELD from '@salesforce/schema/Case.Category__c';

Then use that instead in your call:

@wire(getPicklistValues, {
  recordTypeId: "$caseRecordTypeId",
  fieldApiName: CATEGORY_FIELD
})
3
  • Thanks, Caspar. I did not include the imports here in the code but I have them in my js. import { getObjectInfo, getPicklistValues, getPicklistValuesByRecordType } from "lightning/uiObjectInfoApi"; import { getRecord } from 'lightning/uiRecordApi'; import { refreshApex } from '@salesforce/apex';import Category from "@salesforce/schema/Case.Category__c"; Jun 2, 2022 at 4:21
  • Try using the literal value, ie fieldApiName:"Case.Category__c" (I'm assuming that field exists and is custom and also is visible to the running user) Jun 2, 2022 at 7:07
  • Actually, it's this that is wrong: @wire(getRecord, { recordId: "$selectedCaseId", fields: "RecordTypeId" }) Jun 2, 2022 at 7:16

You must log in to answer this question.

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