4

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

  • 1
    There are a number of critical updates around security and user privileges in Lightning that rolled out at the beginning of the year and are continuing to be released. Ensure that this issue isn't related to one of these critical updates: releasenotes.docs.salesforce.com/en-us/winter20/release-notes/… – nbrown Jan 6 at 15:41
  • 2
    @tkosanke Thank you for the question and welcome to salesforce stackexchange. Could you add Minimum Reproducible Code so we can easily reproduce this issue in dev orgs of Spring20 ? – Mohith Shrivastava Jan 6 at 15:48
  • I looked through the settings and none of the Apex-specific critical updates are activated too. – tkosanke Jan 6 at 16:00
  • Since you're using the Salesforce supplied getRecord, I would look at permissions to see if that's the cause. Can an elevated user like an admin see the data on this component? – nbrown Jan 6 at 16:03
  • 1
    It was my understanding that the Lightning Data Service handles the field level security and object access based on the Profile of the User? Regardless, though, I'm trying to access these records as an administrator in this use case. – tkosanke Jan 6 at 16:12
1

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"
    ]
})

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.