I am trying to connect a web service method to my lightning-datatable. The idea is when the web service is called, my data table will display the returned information. However I am getting an error due to the wire service and HTTP Get method.
I used the following link as a template for my lwc: https://www.salesforcecodecrack.com/2019/10/display-reference-data-in-lwc.html
Currently I get the following error:
[LWC component's @wire target property or method threw an error during value provisioning. Original error:
[t.forEach is not a function]]
HTML:
<template>
<lightning-card title="Static Data" icon-name="standard:record">
<lightning-datatable columns={columns}
data={data}
key-field="id"
hide-checkbox-column="true"
show-row-number-column="true"></lightning-datatable>
</lightning-card>
</template>
JS:
import {LightningElement, track, wire} from 'lwc';
import getData from '@salesforce/apex/WebServiceClass.getMethod';
const columns = [
{
label: 'column1',
fieldName: 'column1',
type: 'text',
}, {
label: 'column2',
fieldName: 'column2',
type: 'date'
}, {
label: 'column3',
fieldName: 'column3',
type: 'text'
}
];
export default class myLWC extends LightningElement {
@track data = [];
@track columns = columns;
@wire(getData)
opp({error, data}) {
if(data) {
let currentData = [];
data.forEach((row) => {
let rowData = {};
if(row.Vouchers){
rowData.column1 = row.column1;
rowData.column2 = row.column2;
rowData.column3 = row.column3;
else{
window.console.log("No data");
}
currentData.push(rowData);
});
this.data = currentData;
}
else if(error) {
window.console.log("Error: " + error);
}
}
}
Apex:
@AuraEnabled(cacheable=true)
@HttpGet
global static InnerClass getMethod(){
InnerClass c = new InnerClass();
return c;
}
// Inner class represent return response
global class InnerClass{
}
EDIT:
To fix this I just removed the for each from my js since I was returning an object not an array