[SalesForce] LWC recordId showing as undefined in Spring ’20

This past weekend, our org was updated to Spring '20 and since our use of recordId and the getRecord method broke. The recordId is undefined when the getRecord method is wired and won't run again even if the recordId variable is set/updated. Is anyone else having this issue? Is there a way to workaround this or force the getRecord wire to re-run?

I've also tried using refreshApex, getting the pageReference and setting the recordId variable, etc.

EDIT:

Added MRC for example. This component was placed directly on the Case page with an Account related to it.

import { LightningElement, api, wire } from 'lwc';
import { getRecord } from 'lightning/uiRecordApi';

export default class TestGetRecord extends LightningElement {
    @api recordId;

    @wire(getRecord, {
        recordId: "$recordId",
        fields: [],
        optionalFields: ["Case.Account.Name"]
    })
    wiredRecord({ error, data }) {
        console.log("recordId: ", this.recordId);
        if (data) {
            console.log("Data: ", data);
        } else if (error) {
            console.log("Error: ", error);
        } else {
            console.log("Both undefined.");
        }
    }
}

The metadata is setting 'isExposed' to true and has a target of 'lightning__RecordPage'.

EDIT2:

Adding a screenshot of the component on the record page. Only visibility settings are shown.

App Builder Screenshot

Best Answer

After further testing, it turns out that the optionalFields property is more restrictive in the update. If an optional field is listed when not looking at the correct record type, it will prevent the wired method from running again when the recordId is updated. In our case, we use the component in both the Case page and Contact page. We had one wire/getRecord method that listed optionalFields for both the Case and Contact record types. After removing the contact fields, the components began loading correctly on the Case page.

To remedy the issue, for now, two separate wire methods were created. One for the Contact page and the other for the Case page.

Old Code:

@wire(getRecord, {
    recordId: "$recordId",
    optionalFields: [
        "Contact.Name",
        "Case.Contact.Name"
    ]
})

New Code:

@wire(getRecord, {
    recordId: "$recordId",
    optionalFields: [
        "Contact.Name"
    ]
})

@wire(getRecord, {
    recordId: "$recordId",
    optionalFields: [
        "Case.Contact.Name"
    ]
})
Related Topic