function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Brooks Johnson 6Brooks Johnson 6 

LWC with Wired Apex and Single Record

Hi Friends, 

I am stuck on what seems like a pretty trivial problem. I have an LWC meant to display on a Lightning App Page. So I can't get the field values by importing (get record)

This component fetches the value of a single record and then I want to display field values in the HTML. But when I load the page. I get an error that the field is undefined. 

If anyone would be kind enough to take a look I would be grateful. ​​​​​

HTML

<template>
    <lightning-card title="Overall Benchmark Values">

        <p>Program Delivery Rate <span>{benchmarks.Program_Mean_Delivery_Rate__c}%</span></p>
    </lightning-card>
</template>
JS
import {LightningElement, wire, track} from 'lwc';
import getBenchmarkValues from '@salesforce/apex/BenchmarksSelector.getOverAllBenchmarks';

export default class OverAllBenchmarks extends LightningElement {
    @track benchMarks;

    @wire(getBenchmarkValues)wiredBenchmark({data, error}){
        if(data){this.benchMarks = data}
        console.log(data);
        console.log(this.benchMarks);
    }
}
The controller
@AuraEnabled(cacheable=true)
	public static BenchMarks__c getOverAllBenchmarks(){
		BenchMarks__c benchMarks = [SELECT Program_Mean_Delivery_Rate__c FROM BenchMarks__c LIMIT 1];
		return benchMarks;
	}


 
Khan AnasKhan Anas (Salesforce Developers) 
Hi Brooks,

Greetings to you!

LWC is case-sensitive. You are using benchmarks in HTML and benchMarks in JS. Use below code:
<template>
    <lightning-card title="Overall Benchmark Values">

        <p>Program Delivery Rate <span>{benchMarks.Program_Mean_Delivery_Rate__c}%</span></p>
    </lightning-card>
</template>

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas