I need to populate my lightning-dual-listbox with the fields of selected object. My apex class returns the list of fields, I have fetched the values in this.objectFields
but they are not getting populated in dual-listbox.
Apex class
@AuraEnabled(cacheable=true)
public static List<String> getObjectFields(String objectName){
system.debug(objectName);
SObjectType objectType = Schema.getGlobalDescribe().get((objectName));
Map<String,Schema.SObjectField> mfields = objectType.getDescribe().fields.getMap();
List<String> sObjectDetailsList = new List<String>();
for(String s : mfields.keySet()){
sObjectDetailsList.add(String.valueOf(mfields.get(s)));
}
return sObjectDetailsList;
}
JS file
@track objectFields = [];
getObjectFields({
objectName: this.selectedObject
})
.then(result => {
var fields = result;
console.log('fields : '+fields);
this.objectFields = fields;
console.log('this.objectFields : '+this.objectFields);
})
.catch(error => {
this.error = error;
console.log('error ===>: ' + error.body.message);
});
HTML File
<lightning-dual-listbox name="Fields"
label="Select Fields"
source-label="Available"
selected-label="Selected"
field-level-help="Select your preferred fields"
options={objectFields}
onchange={handleChange}></lightning-dual-listbox>