Saturday, 10 November 2018


How to find the field data type of particular Object:

In this example,I had taken account as a example

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();
system.debug('field map keyset'+fieldMap.keyset());
system.debug('values###'+fieldMap.values());
for (String fieldName: fieldMap.keySet()) {
//for finding name of the field 
String fieldLabel = fieldMap.get(fieldName).getDescribe().getLabel();
 system.debug('fieldLabel>>>>>'+fieldLabel);
//get data types for each fields like string,datetime etc..
Schema.DisplayType fielddataType = fieldMap.get(fieldName).getDescribe().getType();
    //system.debug('fieldtype>>>'+fielddataType);
    if(fielddataType == Schema.DisplayType.DateTime) {
system.debug('field type*********'+fielddataType);
}
}