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?