My question may be naive as I am new to this area. I need to show all object names list in LWC for which I have written one apex class which returns list of strings as object names. Even though teh list is showing properly in JS, it is not showing data under lightning-datatable in html. Any suggestion?
Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();
Set<String> standardObjects = new Set<String>();
for(Schema.SObjectType d : gd.values()){
Schema.DescribeSObjectResult ds = d.getDescribe();
if(!ds.isCreateable()){
continue;
}
if(ds.isCustom() == false && ds.getRecordTypeInfos().size() > 0){
standardObjects.add(ds.getName());
}
}
In JS, I have used an array to hold all objects and use it as data property of lightning-datatatble in html. I am clueless about keeping the fieldName property of field so I used 'Name'.
JS -
@wire(getAllStandardObjects)
allStdObjs(result){
if(result.data){
this.allStdObjs = [];
var i;
for (i = 0; i < result.data.length; i++) {
var item = {
id: i,
objectName: result.data[i],
};
this.allStdObjs.push(item);
console.log('std obj list came:'+this.allStdObjs[i].objectName);
}
this.error = undefined;
}else if(result.error){
this.error = result.error;
this.data = undefined;
}
}
@track columns = [
{
label : 'Name',
fieldName : 'name',
type : 'text'
},
{
label : 'Action',
fieldName : 'action',
type:'button',
fixedWidth: 150,
typeAttributes: {
label: 'Show Fields',
name: 'showfields',
variant: 'brand'
}
}
];
HTML -
<lightning-datatable
class="slds-border_top"
key-field="id"
columns={columns}
data={allStdObjs}
default-sort-direction={defaultSortDirection}
sorted-direction={sortDirection}
sorted-by={sortedBy}
onsort={onHandleSort}>
</lightning-datatable>