1

Hello I started learning Lwc, I have problem with chained @wire function call, which always returns [object Object] instead of field values.

Controller

public class LastMonthStatementComparatorController {

    @AuraEnabled(cacheable=true)
    public static Bank_Statement__c getPreviousMonthStatement(String statementName) {
        return [SELECT Name, Income__c, Outcome__c FROM Bank_Statement__c WHERE Name = :statementName];
    }
}

@wire annotaded variable which works:

    @wire(getRecord, { recordId: '$recordId', fields: [BS_INCOME, BS_OUTCOME, BS_NAME] }) currentBs({err,data}) {
        if(data) {
           this.previousBsName = this.parsePreviousBsName(getFieldValue(data, BS_NAME));
           this.currentData = data;
           console.log(data)
        } else if(err) {
            console.error(err);
        }
    }

second @wire that is executed after first one

    @wire(getPreviousMonthStatement, { statementName: '$previousBsName' }) previousBs({err,data}) {
        if(data) {
            this.previousData = data; //here it works, json is retrieved successfully.
        } else if(err) {
            console.log(err) 
        }
    }

getters

    get currentIncome() {                                   ====> returns valid value
        return getFieldValue(this.currentData, BS_INCOME);
    }

    get previousIncome() {                                  ====> returns [object Object]
        console.log(this.previousData)                      ===> it returns valid JSON
        return getFieldValue(this.previousData, BS_INCOME); ===> it returns [object Object]
    }

HTML

<template>
        <lightning-card  title='test'>
            <p class="slds-m-top_medium">{currentIncome}</p>
            <p class="slds-m-top_medium">{previousIncome}</p>
            <p slot="footer">Card Footer</p>
        </lightning-card>
    </template>
</template>

Where's the problem?

1 Answer 1

1

You'll want to return "this.previousData.Income__c" in your: get previousIncome()

When using the "getRecord" imported method, you are using the User Interface API, which will return a uniquely formatted data object: https://developer.salesforce.com/docs/atlas.en-us.uiapi.meta/uiapi/ui_api_responses_record.htm

You can use all the other UI API functions like getFieldValue on the above data type, but using your own Apex methods to return an SObject "Bank_Statement__c" record you essentially return a map<string, object>.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.