I am trying to return some data from a wrapper class into my LWC component but keep getting errors whatever I try.
Whenever I load the page, I get property 'icon' undefined.
Here is my current code:
HTML
<template>
{recordType.icon}
<template>
JS
import { LightningElement, api, wire } from 'lwc';
import getRecordType from '@salesforce/apex/ChatterUtils.getRecordType';
export default class ChatterPost extends LightningElement {
@api post;
recordType;
@wire(getRecordType, {recordId: '$post.Id'})
retrieveType(result) {
this.recordType = result.data;
}
}
Apex
@AuraEnabled(Cacheable=true)
public static CustomWrapper getRecordType(Id recordId) {
CustomWrapper cw = new CustomWrapper();
cw.icon = 'dummy-icon';
cw.styleClass = 'dummy-class';
return cw;
}
public class CustomWrapper {
@AuraEnabled
public String icon {get; set;}
@AuraEnabled
public String styleClass {get; set;}
public CustomWrapper() {
this.icon = 'default-icon';
this.styleClass = 'default-style';
}
}