import { getRecord, getFieldValue } from 'lightning/uiRecordApi';
import FIELD1 from '@salesforce/schema/Account.SumOpp__c';
import FIELD2 from '@salesforce/schema/Account.Name';
const fields = [FIELD1, FIELD2];
@wire(getRecord, { recordId: '$recordId', fields })
account;
get field1() {
return getFieldValue(this.account.data, FIELD1);
}
get field2() {
return getFieldValue(this.account.data, FIELD2) + ' ' + this.field1;
}
-
Are you getting any errors?– Caspar HarmerApr 7 at 20:04
-
If this is meant to be a self-answered question, which we certainly encourage, the section above this comment should be a self-contained question, and the area below should contain the example solution. You can edit your question and add your own answer below.– sfdcfoxApr 7 at 20:07
1 Answer
If you want to concatenate two values, your approach looks ok - you could make it a bit clearer by making a third getter to do it though:
get field2() {
return getFieldValue(this.account.data, FIELD2);
}
get concatenatedFields(){
return `${this.field1} ${this.field2}`;
}
-
I did in this way and put this variable in label of accordion, but displays Undefined Undefined : <lightning-accordion> <template if:true={data}> <template for:each={data} for:item="acc"> <lightning-accordion-section key={acc.Id} name={acc.Name} label={concatenatedFields}> Mayby you know how resolve it? Thanks!– annatApr 7 at 20:27
-
You don't have a
recordId
class attribute defined.@api recordId;
Also amend the top to:import { LightningElement, api, wire } from 'lwc';
Apr 7 at 20:29