Skip to main content

Hello,

 

I was hoping someone might be able to help me with an issue I'm having. 

Context: I'm making an LWC on an experience cloud site which will show the values set in a custom setting. These values will change hourly and I have a scheduled apex with controller handling that (this part is working correctly). However, I keep running into issues showing these field values within my LWC. I  get the following error: "Uncaught (in promise) ReferenceError: LWC component's @wire target property or method threw an error during value provisioning. Original error: [customSetting is not defined]"

 

I created a wrapper which returns the values of the custom setting. I've already created a default value for the custom setting and am using the getOrgDefaults() method. The apex controller is calling the same method and it seems to work as the custom setting is being updated properly. I've also added the custom setting to my profile (system administrator) just in case it was potentially something related to permissions. My issue is with the LWC where it seems to never receive the value? The @wire method always comes back undefined. Any help is appreciated!

 

Here's my code:

Wrapper class

public class StockWrapper {	@AuraEnabled(cacheable=true)    public static Stock_Price__c getCustomSetting(){        return Stock_Price__c.getOrgDefaults();    }}

.JS

import { LightningElement, wire, track } from 'lwc';import getCustomSetting from '@salesforce/apex/StockWrapper.getCustomSetting';export default class StockPrice extends LightningElement {    @track date;    @track timeStamp;    @track closePrice;    @wire(getCustomSetting)    customSetting({error, data}){        if(data) {            this.closePrice = customSetting.data.Stock_Price__c;            date = new Date(customSetting.data.Stock_Timestamp__c * 1000);            timeStamp = date.toLocaleString();        }         else if (error) {            this.error = undefined;        }    }}

 

#Salesforce Developer

2 Antworten
  1. 3. Apr. 2024, 18:25

    Hi @Jonathan Jimenez

     

    Your LWC js code seems incorrect, I have updated the code, try this one

    import { LightningElement, wire, track } from 'lwc';

    import getCustomSetting from '@salesforce/apex/StockWrapper.getCustomSetting';

    export default class StockPrice extends LightningElement {

    @track date;

    @track timeStamp;

    @track closePrice;

    @wire(getCustomSetting)

    customSetting({error, data}){

    if(data) {

    this.closePrice = data.Stock_Price__c;

    let date = new Date(data.Stock_Timestamp__c * 1000);

    this.timeStamp = date.toLocaleString();

    }

    else if (error) {

    this.error = undefined;

    }

    }

    }