1

This error has recently appeared for me again on an LWC, but only the very first time I open a page for this record type after logging into the org - thereafter never again for my session. And I can't replicate this in my Dev sandbox at all - only in my production org and QA (which is a full sandbox). The only time I get it again is if I log out of the org and back in again. It is extremely frustrating as I don't understand what the problem is.

I would appreciate any help in sorting this out.

enter image description here

My HTML:

<div class="slds-card__body slds-card__body_inner">
<div class="slds-var-m-around_medium slds-text-heading_small">
  <template if:true={reasonPicklistValues.data}>
    <lightning-combobox
      name="reason"
      label="Select a reason"
      value={value}
      placeholder="-Select-"
      options={reasonPicklistValues.data.values}
      onchange={handleChange}
      class="slds-var-m-around_x-small">
    </lightning-combobox>
  </template>
</div>
</div>

And my JS:

  @api recordId;
  @api objectApiName;

  @track objectInfo;

  @wire(getObjectInfo, { objectApiName: CERTIFICATE_OBJECT })
  objectInfo;
  get recordTypeId() {
    if (this.objectInfo.data) {
      if (this.objectInfo.data.recordTypeInfos) {
        const rtis = this.objectInfo.data.recordTypeInfos;
        return Object.keys(rtis).find(
          (rti) => rtis[rti].name === "XYZ Certificate"
        );
      }
    }
    return null;
  }

  @wire(getPicklistValues, {
    recordTypeId: "$recordTypeId",
    fieldApiName: GENERATEMANUALREASON_FIELD
  })
  reasonPicklistValues;
2
  • I would be explicit with my JS checks, coz JS is flimsy. So instead of if(what) i would do if(what != null)
    – zaitsman
    Commented Jan 22, 2021 at 1:02
  • Any reason you've got two objectInfo variables? I'm guessing this is going to create confusion. The wire function will store the results in the objectInfo declared below it. You don't need the @track objectInfo variable.
    – Nick C
    Commented Jan 22, 2021 at 3:22

1 Answer 1

1

I've reproduced your code in a simplified snippet and it does work for me. I think your error may be happening because what @Nick Cook said in a comment - As @wire tracks the property already, so you don't need to @track it. Here you have the simplified code for reference:

import { LightningElement, wire, api } from "lwc";
import { getObjectInfo } from "lightning/uiObjectInfoApi";
import ACCOUNT_OBJECT from "@salesforce/schema/Account";

export default class RecordTypesError extends LightningElement {
  @api recordId;
  @api objectApiName;

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

  get recordTypeId() {
    if (this.objectInfo.data) {
      if (this.objectInfo.data.recordTypeInfos) {
        const rtis = this.objectInfo.data.recordTypeInfos;
        return Object.keys(rtis).find((rti) => rtis[rti].name === "test");
      }
    }
    return null;
  }

You must log in to answer this question.

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