I am trying to display the account name in the HTML by fetching the data from apex controller. The getter method in the JS file is used to fetch the data from apex using the wire method and return the account name in HTML but the name is not displaying at the moment. What could be the issue?
HTML:
<template>
<lightning-card title="My Account Record" icon-name="standard:account">
<div class="slds-m-around_medium">
<p>My name is : {myname}</p>
</div>
</lightning-card>
</template>
JS:
import { LightningElement, wire, api} from 'lwc';
import getRecord from '@salesforce/apex/AccountController.getAccounts';
const FIELDS = [
'Account.Name',
'Account.Industry',
'Account.Rating',
'Account.Website',
];
export default class FetchDataFromApex extends LightningElement {
@api recordId;
@wire(getRecord, {recordId: '$recordId', fields: FIELDS}) record;
@api
get myname() {
return this.record.data.fields.Name.value;
}
@api
get myindustry() {
return this.record.data.fields.Industry.value;
}
@api
get myrating() {
return this.record.data.fields.Rating.value;
}
@api
get mywebsite() {
return this.record.data.fields.Website.value;
}
}
Apex:
public without sharing class AccountController {
//account controller class
@AuraEnabled(cacheable = true)
public static List<Account> getAccounts()
{
return [SELECT Id, Name, Industry, Rating, Website, AnnualRevenue FROM Account LIMIT 25];
}
}