I am new to LWC. Kindly help me.
I am trying to fetch value from controller class in LWC component. But every time I try to fetch value from controller class, it comes as undefined.
Here is my code: controller class
public without sharing class contactController {
@AuraEnabled (cacheable= true)
public static String getAccountExtId(String contactId){
String accExtId;
List <Contact> contactRecord = [select Account.CodeClientLEMS__c , AccountId from Contact where Id= :contactId];
accExtId = contactRecord[0].Account.CodeClientLEMS__c;
return accExtId;
}
}
.Js
import { LightningElement, wire, api } from 'lwc';
import LOGO from "@salesforce/resourceUrl/CustomPortal_Logo";
import getAccountExtId from '@salesforce/apex/contactController.getAccountExtId';
export default class Logo_CustPotal extends LightningElement {
@api recordId;
contacts;
@wire(getAccountExtId,{contactId:'$recordId'})
wiredAccount({ data, error })
{
if (data) {
console.log('checking the data', data);
this.contacts = data;
} else if (error) {
console.log('Something went wrong:', error);
}
}
coustomPortalLogo = LOGO + '/Logos/'+this.contacts+'.png';
}
html
<template>
<lightning-card >
<div style="width: 15%; display: block;margin-left: auto;margin-right: auto;">
<img src={coustomPortalLogo}>
</div>
</lightning-card>
</template>
