1

tl; dr - How do I fix the error message shown in the screenshot below?

Overview

I am attempting to create a lightning web component that displays the field values of a record related to an Event record. Initial testing with a hard-coded record Id was successful, but attempts to dynamically acquire the record Id from a lookup field on the Event record have proven difficult.

With the assistance of user Avi Rai I was able to use get the needed field values from an apex call, and the component is now showing the correct, record-specific field data. However, despite the record being correctly found, a large red error message appears at the top of the component reading "Error in fetching record: invalid record id."

Question

Why is his error message occurring (despite the fact that the record is being correctly found), and what can I do to remove this error message?

Screenshot of error:

enter image description here

html

<template>
    <lightning-card title="Meeting Notes">
            <p class="slds-p-horizontal_small">
                <lightning-record-edit-form record-id={meetingNotesId} object-api-name="Meeting_Note__c">
                    <lightning-messages></lightning-messages>
                    MeetingNoteId : --|{meetingNotesId}|--
                    <lightning-input-field field-name="Running_Log_Coaching__c"></lightning-input-field>
                    <lightning-input-field field-name="Running_Log_Financial_Services__c"></lightning-input-field>
                    <lightning-button
                        class="slds-m-top_small"
                        variant="brand"
                        type="submit"
                        name="update"
                        label="Update">
                    </lightning-button>
                </lightning-record-edit-form>
            </p>
    </lightning-card>
</template>

js

import { LightningElement, api, wire } from 'lwc';
import { getSObjectValue } from '@salesforce/apex';
import getMeetingNote from '@salesforce/apex/TaskEventUtility.getMeetingNote';

import ID_FIELD from '@salesforce/schema/Meeting_Note__c.Id';

export default class DisplayMeetingNotes extends LightningElement {
    @api recordId;

    @wire(getMeetingNote, { eventId: '$recordId'})
    meeting;

    get meetingNotesId(){
        return this.meeting.data ? getSObjectValue(this.meeting.data, ID_FIELD) : 'Bob';
    }

}

apex

 @AuraEnabled(cacheable=true)
 public static Meeting_Note__c getMeetingNote(Id eventId){
     Id meetingNoteId = [SELECT Id, Meeting_Notes__c FROM Event WHERE Id = :eventId LIMIT 1].Meeting_Notes__c;
     return [SELECT Id, Running_Log_Coaching__c, Running_Log_Financial_Services__c,
                FROM Meeting_Note__c WHERE Id = :meetingNoteId];
 }
  • 1
    Don't return 'Bob' if there is no data in meeting.data... return null – Caspar Harmer Mar 4 at 22:12
1

So I think the error is there because in the time between retrieving the Meeting_Note__c record, the RecordEditForm is being supplied with an Id of 'Bob'.

'Bob' is an invalid id - while I know eventually you provide a valid id, you should change this to null (or perhaps ""). This will mean the form won't complain and you won't get that nasty red error message.

| improve this answer | |

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.