[SalesForce] getFieldvalue is giving undefined in LWC

I am trying to get a field value of a record in LWC. I am getting the data as undefined. It is a checkbox, i am expecting True or False in the data.

What i am missing?

    import { LightningElement, api, wire} from 'lwc';
    import { getRecord, getFieldValue } from 'lightning/uiRecordApi';
    import { ShowToastEvent } from 'lightning/platformShowToastEvent';
    import SalePriceGreaterMaxLoan from 
     '@salesforce/schema/SBQQ__Quote__c.Is_Sale_Price_Greater_than_Max_Loan__c';    


    export default class SalePriceGreaterThanMaxLoan extends LightningElement {
    @api recordId;

    @wire (getRecord, {recordId: '$recordId', fields: [SalePriceGreaterMaxLoan]})
    quote;

    renderedCallback(){
        //const record = {}
        console.log(this.recordId);
        console.log(this.quote.data);
        const Salepricevalue = getFieldValue (this.quote.data , SalePriceGreaterMaxLoan);
        console.log(Salepricevalue);
        //alert("sale price"+Salepricevalue);
        if(Salepricevalue === true){
            const evt = new ShowToastEvent({
                title: 'Application Warning',
                message: 'Sale Price is greater than Max loan Approved.',
                variant: 'warning',
                mode: 'dismissable'
            });
            this.dispatchEvent(evt);
        }

    }
}

Best Answer

In your use case, it might be an option to use a wired function instead of a wired property. In this way you can be sure that the record has already been fetched correctly from the database. Pseudo code:

@wire (getRecord, {recordId: '$recordId', fields: [SalePriceGreaterMaxLoan]})
quote(result){
  if(result.data){
    //use getFieldValue and show your toast 
  }
  else if(result.error)
  {
    //something went wrong
  }
}
Related Topic