You need to sign in to do that
Don't have an account?
Sandeep Ekambe
Unable to fetch custom object record into LWC using getRecord(), wire adapter
Hello All,
Trying to display single field(age__c) from a custom object(MVStudent__c) but its displaying blank on the record page.
Below is the code, please help me out.
loadRecord2.js
Trying to display single field(age__c) from a custom object(MVStudent__c) but its displaying blank on the record page.
Below is the code, please help me out.
loadRecord2.js
import { LightningElement, api, wire } from 'lwc'; /* Wire adapter to fetch record data */ import { getRecord, getFieldValue } from 'lightning/uiRecordApi'; import MVSTUDENT_OBJECT from '@salesforce/schema/MVStudent__c'; import AGE_FIELD from '@salesforce/schema/MVStudent__c.Age__c'; export default class AccountViewer extends LightningElement { /** Id of record to display. */ @api recordId; /* Expose schema objects/fields to the template. */ mvstudentObject = MVSTUDENT_OBJECT; /* Load Account.Name for custom rendering */ @wire(getRecord, { recordId: '$recordId', fields: [AGE_FIELD] }) record; /** Get the Account.Name value. */ get ageValue() { return this.record.data ? getFieldValue(this.record.data, AGE_FIELD) : ''; } }loadRecord2.html
<template> <lightning-record-view-form record-id={recordId} object-api-name={mvstudentObject}> <div class="slds-grid"> <div class="slds-col slds-size_1-of-2"> <!-- Other record data here --> </div> <div class="slds-col slds-size_1-of-2"> <lightning-formatted-text value={ageValue} class="slds-text-heading_large"> </lightning-formatted-text> </div> </div> </lightning-record-view-form> </template>