function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Display object fields and their datatype in Aura


I have requirement to search for an object and then display their related field names and field datatype using aura. Can anyone help me with this. 

ShivankurShivankur (Salesforce Developers) 
Hi Raghu.2020,

Below is the piece of Apex code which would return you the given object's Field Names and their Data Types:
String objType='Account';
Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
Schema.SObjectType leadSchema = schemaMap.get(objType);
Map<String, Schema.SObjectField> fieldMap = leadSchema.getDescribe().fields.getMap();

for (String fieldName: fieldMap.keySet()) {
    //get all the fields label for Account Object
    String fieldLabel = fieldMap.get(fieldName).getDescribe().getLabel();
    //get data types for each fields
    Schema.DisplayType fielddataType = fieldMap.get(fieldName).getDescribe().getType();
    System.debug('Field Name: '+ fieldLabel+' Field Data Types: '+fielddataType);

This example is for 'Account' object, you can verify the result by running above code directly into developer console using Anonymous window.

Once you have the results ready in your Apex(in variable fieldLabel & fielddataType), you can display the results into your Aura components the way you want, may be in a fancy way too..

You can find example on how to write an Aura component to display values retrieved in Apex on below link:


Hope above information helps, Please mark as Best Answer so that it can help others in the future.

Hi Shivankur,

Thanks for your reply. I'm facing difficulty showing them in a datatable since the examples you provided were discussing about object which will have key value as Id. But in my case, I have two lists of strings and not sure how to return both and display them in datatable.