function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
JeffreyStevensJeffreyStevens 

lwc wrapper class

I'm working on some more LWC learning - trying to understand how a custom wrapper class is displayed in the component.

If I have this APEX, .js, and HTML - the value of field1 is never displayed - can anyone see my issue?

Thanks!

APEX:
@AuraEnabled(cacheable=true)
	public static wrapperClass  rtnWrapperClass(){
		wrapperClass wrapper = new wrapperClass();
		wrapper.field1 = 'Value for field1';
		wrapper.field2 = 'Value for field2';
		return wrapper;
	}

	public class wrapperClass {
		@AuraEnabled 	public string  	field1		{get;set;}
		@AuraEnabled 	public string 	field2		{get;set;}
		public wrapperClass() {
			this.field1 = field1;
			this.field2 = field2;
		}
	}
.js
import rtnWrapperClass from '@salesforce/apex/HelperAccount.rtnWrapperClass';

export default class showWrapper extends LightningElement {

    // Return  Wrapper Class
    @wire(rtnWrapperClass)
        wrapperClass;

}

and the HTML:
<!-- Data from Wrapper Class -->
            <p>Wrapper Class Data...</p>
            <template if:true={wrapperClass.data}>
                <lightning-formatted-text
                    value={wrapperClass.field1}>
                </lightning-formatted-text>
            </template>



 
Best Answer chosen by JeffreyStevens
Khan AnasKhan Anas (Salesforce Developers) 
Hi Jeffrey,

Greetings to you!

Please try below code:
<!-- Data from Wrapper Class -->
            <p>Wrapper Class Data...</p>
            <template if:true={wrapperClass.data}>
                <lightning-formatted-text
                    value={wrapperClass.data.field1}>
                </lightning-formatted-text>
            </template>

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas

All Answers

Khan AnasKhan Anas (Salesforce Developers) 
Hi Jeffrey,

Greetings to you!

Please try below code:
<!-- Data from Wrapper Class -->
            <p>Wrapper Class Data...</p>
            <template if:true={wrapperClass.data}>
                <lightning-formatted-text
                    value={wrapperClass.data.field1}>
                </lightning-formatted-text>
            </template>

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
This was selected as the best answer
JeffreyStevensJeffreyStevens
Yep - that was it - Thanks!