I have been following this guide to create a Web Component that gets a records information, however I am having trouble getting this to work with custom object... Is there extra steps you need to take to get this to work with custom objects?
For example, here is what I have in my own code:
import { LightningElement, api, wire} from 'lwc';
import { getRecord, getFieldValue } from 'lightning/uiRecordApi';
const STUDENT_FIELDS = [
'Student__c.Name',
'Student__c.username__c'
]
export default class StudentCourseRelationship extends LightningElement {
@api recordId;
// STUDENT
@wire(getRecord, { recordId: '$recordId', STUDENT_FIELDS}) student;
get studentName() {
// OPTION 1
return getFieldValue(this.student.data, STUDENT_FIELDS[0]);
// OPTION 2
return this.student.data.fields.Name.value
}
get studentUsername() {
// OPTION 1
return getFieldValue(this.student.data, STUDENT_FIELDS[1]);
// OPTION 2
return this.student.data.fields.username__c.value
}
}
As you can see, in my get
methods I have explained 2 options. In Option 1
, nothing errors but nothing is displayed in the view where I attempt to display studentName
and studentUsername
. And in Option 2
, I get the error: [undefined is not an object (evaluating 'this.student.data.fields')]