How to use Wrapper Class in lwc
This is a quite common problem, with wrapper class if you use same name of property and the parameters of the constructor; you should use 'this' keyword to assign parameter value to property.
public class wrapp{
@AuraEnabled
public Contact con{get;set;}
@AuraEnabled
public boolean selected{get;set;}
public wrapp(boolean selected,Contact con){
this.con = con;
this.selected = selected;
}
}
As an alternative, this is how you would approach the same thing but without a public wrapper.
You would leverage the very interesting datatype Map<String, Object>
in lieu of an actual wrapper class.
@AuraEnabled (cacheable=true)
public static List<Map<String, Object>> getWrapper() {
List<Map<String, Object>> wrapperList = new List<Map<String, Object>>();
for (Contact contact : [SELECT Id, Name, Title, Phone, Email FROM Contact LIMIT 100]) {
Map<String, Object> wrapp = new Map<String, Object>{
'selected' => false,
'con' => contact
};
wrapperList.add(wrapp);
}
return wrapperList;
}