tl; dr - How do I access a custom field value on the Event object via lwc?
Update at bottom of page
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 not been.
In my Html file, I created two lines for testing purposes to show the values I am looking for.
MeetingId : --|{meetingId}|--
MeetingNoteId : --|{meetingNoteId}|--
When the {meetingNoteId}
is commented out, {meetingId}
populates fine. But when {meetingNoteId}
is not commented out, neither field populates. The field that {meetingNoteId}
is capturing is a custom field called Meeting_Notes__c
, a lookup field to a custom object. Because it is a custom field, it is technically on the Activity
object, but "@salesforce/schema/Activity.Meeting_Notes__c" causes an error, whereas "@salesforce/schema/Event.Meeting_Notes__c" does not.
Question
What changes need to be made to my @wire or import code to allow the component to access the custom field value on the Event object?
Code
displayMeetingNotes.html
<template>
<lightning-card title="Meeting Notes">
<p class="slds-p-horizontal_small">
<lightning-record-edit-form record-id="a1k1Y00000FB6xUQAT" object-api-name="Meeting_Note__c">
<lightning-messages></lightning-messages>
MeetingId : --|{meetingId}|--
MeetingNoteId : --|{meetingNoteId}|--
<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>
displayMeetingNotes.js
import { LightningElement, api, wire } from 'lwc';
import { getRecord, getFieldValue } from 'lightning/uiRecordApi';
// const fields = ['Event.Meeting_Notes__c'];
import EVENT_ID from '@salesforce/schema/Event.Id';
import MEETING_NOTE_ID from '@salesforce/schema/Event.Meeting_Notes__c';
export default class DisplayMeetingNotes extends LightningElement {
@api recordId;
@wire(getRecord, { recordId: '$recordId', fields:[MEETING_NOTE_ID, EVENT_ID]})
meeting;
get meetingNoteId(){
return getFieldValue(this.meeting.data, MEETING_NOTE_ID);
}
get meetingId(){
return getFieldValue(this.meeting.data, EVENT_ID);
}
}
----- Updated Code here ------
Switching to an apex based data call is still not yielding the field values.
apex
@AuraEnabled(cacheable=true)
public static Event getEvent(Id eventId) {
return [
SELECT Id, Meeting_Notes__c
FROM Event
WHERE Id = :eventId
];
}
html
<template>
<lightning-card title="Meeting Notes">
<p class="slds-p-horizontal_small">
<lightning-record-edit-form record-id="a1k1Y00000FB6xUQAT" object-api-name="Meeting_Note__c">
<lightning-messages></lightning-messages>
MeetingId : --|{meetingId}|--
<!-- MeetingNoteId : --|{meetingNoteId}|-- -->
<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>
javascript
import { LightningElement, api, wire } from 'lwc';
import { getRecord, getFieldValue } from 'lightning/uiRecordApi';
import getEvent from '@salesforce/apex/TaskEventUtility.getEvent';
import { getSObjectValue } from '@salesforce/apex';
export default class DisplayMeetingNotes extends LightningElement {
@api recordId;
@wire(getEvent, { eventId: '$recordId'})
meeting;
get meetingId() {
return this.meeting.data ? getSObjectValue(this.meeting.data, 'Id') : 'No Data';
}
}