0

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

9
  • Is there a reason you are not using the uiRecordApi getRecordUi to fetch this information efficiently and without the need to write your own server-side code? It has the benefit of presenting relevant schema details for the current user based on the assigned layout and permissions.
    – Phil W
    Mar 30, 2020 at 8:11
  • I would also suggest you avoid using the Schema.getGlobalDescribe API as this is notoriously expensive. Take a look at this answer for more.
    – Phil W
    Mar 30, 2020 at 8:16
  • @PhilW Please tell me the code how to fetch the object Fields label and value using uiRecordApi Mar 30, 2020 at 8:23
  • Take a look at the getRecordUi documentation.
    – Phil W
    Mar 30, 2020 at 8:37
  • Follow the link to the Record UI description that takes you down to the Field that includes the "label" property you want.
    – Phil W
    Mar 30, 2020 at 8:37

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.