I am not able to pull any of the related records to the account dataTable. I want to see the related records for Trade_Lanes__c on the data table, but nothing shows up. Below is my code.
Apex Controller:
public with sharing class AccountRelatedObj {
@auraEnabled(cacheable=true)
public static List<Trade_Lane__c> getContactsRelatedToAccount(String accId) {
system.debug('accId >> ' + accId);
return [SELECT Name, Annual_Ocean_Volume__c,Annual_Air_Volume_kg__c, Annual_Road_Volume_cbm__c from Trade_Lane__c where AccountId__c = :accId];
}
HTML:
<template>
<lightning-card title="LWC Record Id Example ">
<lightning-datatable data={TradeLanes} columns={columns} key-field="Id">
</lightning-datatable>
</lightning-card>
</template>
JS:
import { LightningElement, track, wire, api } from 'lwc';
import getContactsRelatedToAccount from
'@salesforce/apex/AccountRelatedObj.getContactsRelatedToAccount';
export default class AccountRelatedContacts extends LightningElement {
@api recordId;
@track TradeLanes;
@track columns = [
{ label: 'Name', fieldName: 'name' },
{ label: 'Ocean Volume', fieldName: 'annual_ocean_volume__c' },
{ label: 'Air Volume', fieldName: 'annual_air_volume_kg__c'},
{ label: 'Road Volume', fieldName: 'annual_road_volume_cmb__c'},
];
@wire(getContactsRelatedToAccount, {accId: '$recordId'})
WireContactRecords({error, data}){
if(data){
this.contacts = data;
this.error = undefined;
}else{
this.error = error;
this.contacts = undefined;
}
}
}
Best Answer
Two things, here. First, you're assigning to
this.contacts
, which is the wrong variable. Secondly, JavaScript is cAsE-sEnSiTiVe. I suspect you're not seeing your data because thefieldName
properties are all lowercase. You can, and should, import the field names to avoid case sensitivity problems.As a side note, you're not translating the data in your wire handler, so you may as well just get rid of it.