I am using Apex class to fetch all the fields of the SObject. And i want to display all the field label into the component so i am using lwc to create a component Successfully ii am getting all the Case fields in the component but the field label is not visible
Below is the Apex code // class 1
public class ComboBoxModel
{
public String fieldLabel;
public String fieldValue;
}
//Class 2
public class GetEfilesUsingSOQLQuery {
@AuraEnabled
public static List<ComboBoxModel> fetchObjectFields(objectName)
{
List<ComboBoxModel> cbModels = new List<ComboBoxModel>();
List<String> CustomlistViewFields = new List<String>();
Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
Schema.SObjectType leadSchema = schemaMap.get(objectName);
Map<String, Schema.SObjectField> fieldMap = leadSchema.getDescribe().fields.getMap();
for (String fieldName: fieldMap.keySet()) {
System.debug('##Field API Name='+fieldName);// list of all field API name
CustomlistViewFields.add(fieldMap.get(fieldName).getDescribe().getLabel());//It provides to get the object fields label.
}
for(String temp: CustomlistViewFields){
ComboBoxModel cbModel = new ComboBoxModel();
cbModel.fieldValue = temp;
cbModel.fieldLabel = temp;
cbModels.add(cbModel);
}
return cbModels;
}
}
Below is Html code
<lightning-combobox
name="Field Name"
label="Field Name"
placeholder="Choose Field"
value={selectedFieldValue}
onchange={handleFieldValueChange}
options={FieldsName}>
Below is the js code
handleOpenFilterModalBox()
{
getCustomListViewFields().then(data=>{
if(data)
{
for(var i=0; i<data.length; i++) {
console.log('id=' + data[i].fieldValue);
this.FieldsName = [...this.FieldsName ,{value: data[i].fieldValue , label: data[i].fieldLabel}];
}
}
this.dispatchEvent(
new ShowToastEvent({
title: 'Success!!'+this.FieldsName,
message: '',
variant: 'Success',
}),
);
}).catch(error=>{
this.dispatchEvent(
new ShowToastEvent({
title: 'Error!!'+error.message,
message: '',
variant: 'error',
}),
);
})
}
So tell me how to display the field label in the Combobox