I'm trying to build a Dynamic list(table) of records by selecting the Sobject and its fields.So I need to get all the fields with its API name,label,type.But I can't get the label and type.(Tried DescribeSObjectResult Class methods to get label,but it didn't help to get the label dynamically) I tried it with the following code.
System.debug('Selection-----'+selectedObject);
Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();
Schema.SObjectType ctype = gd.get(selectedObject);
Map<String, Schema.SobjectField> fmap = ctype.getDescribe().fields.getMap();
List<FieldWrap> strList = new List<WrapMap>();
for(String s: fmap.keySet()) {
WrapMap wmp = new WrapMap();
wmp.name = s;
wmp.label = String.valueOf(fmap.get(s));
strList.add(wmp);
}
Where FieldWrap
is my wrapper class with name and field of String types.
I'm getting the List of API name of fields,but not the Label and type of it.Is there a way to get the label and type of field.If so, please help me.