In my LWC component JS, I have used @wire to query the current values of 2 fields (name and mobile) direct from a record in Salesforce. I am saving these values into a list.
I have another method getEmpWrapperList inside connectedCallback() which queries same fields (name and mobile) but it's using existing Apex class because it needs to query these info from a legacy system & not directly from Salesforce records.
I want to combine both results into one list - results from my @wire and the one from getEmpWrapperList.
Basically, I would want to combine savedEmpObj and this.empWrapperList results. But since connectedCallback() and @wire are self-invoked, how do I do achieve this?
emp.JS
@wire(getRecord, { recordId: '$record.Id', fields: ["Object__c.Name__c","Object__c.Mobile__c"] })
empRecord({ error, data }) {
if (error) {
console.log('error in wire', error);
} else if (data) {
this.empRecordName = data.fields.Name__c.value;
this.empRecordMobile = data.fields.Mobile__c.value;
let savedEmpObj = {};
savedEmpObj.empName = this.empRecordName;
savedEmpObj.empMobile = this.empRecordMobile;
}
}
connectedCallback() {
getEmpWrapperList({ empid: this.empid, org: this.org, empcode: this.empcode }) //Apex class to fetch data from integrated system
.then(result => {
this.empWrapperList = result; //contains Name, Mobile from integrated system
this.error = undefined;
})
.catch(error => {
this.error = error;
this.empWrapperList = undefined;
});
}