how to i get datatype of any filed in SOQL?


we can get the all the standard and custom objects fields data types using the getGlobalDescribe, getDescribe, getType.

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();
    if(fielddataType == Schema.DisplayType.TextArea) {
        /* build your logic if the Field data type is TextArea */

    if(fielddataType == Schema.DisplayType.String) {
        /* build your logic if the Field data type is String */

    if(fielddataType == Schema.DisplayType.Integer) {
        /* build your logic if the Field data type is Integer */

    if(fielddataType == Schema.DisplayType.DateTime) {
        /* build your logic if the Field data type is DateTime */


Here Schema.DisplayType enum value is returned by the field describe result’s getType method.

Click here for more details:


  • 1
    It should be == instead of != – BarCotter Jul 20 '15 at 10:32
  • ohhh yaa thanx!!! will update – Arjun Khatri Jul 20 '15 at 10:33

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.