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
Priyanka Reddy 74Priyanka Reddy 74 

How to filter decimal / double data type feilds

Hi All,

Im trying to retrive only Double datatype feilds from Schema.DescribeFieldResult can some one suggest how to filter based on feild datatype and store feild names in list.
String editableFields =' ';
List<String> allFieldName = new List<String>();

Map<String, Schema.SobjectField> allMap = Schema.SobjectType.Account.fields.getMap();
        for(Schema.SobjectField field : allMap.values())
        {  
            Schema.DescribeFieldResult dfr = field.getDescribe();
            if(dfr.isCreateable() && dfr.isUpdateable() ){
                allFieldName.add(dfr.getName());                   
                editableFields += ','+ dfr.getName();
                 system.debug(dfr.getName() +' : '+ dfr.getType());
                    
                }
        }

Thank you.
AnudeepAnudeep (Salesforce Developers) 
Hi Priyanka, 

The DescribeFieldResult Class contains getType() method. I recommend using that method. Here is an example code I found online
String type='MyCustObject_c';
        Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
        Schema.SObjectType leadSchema = schemaMap.get(type);
        Map<String, Schema.SObjectField> fieldMap = leadSchema.getDescribe().fields.getMap();
     
        for (String fieldName: fieldMap.keySet()) {
 
        //It provides to get the object fields label.
        String fieldLabel = fieldMap.get(fieldName).getDescribe().getLabel();
 
       //It provides to get the object fields data type.
        Schema.DisplayType fielddataType = fieldMap.get(fieldName).getDescribe().getType();
         if(fielddataType != Schema.DisplayType.TextArea)
               //do something
         if(fielddataType != Schema.DisplayType.String)
               //do something
 
         }

Let me know if this helps, if it does, please close the query by marking it as solved. It may help others in the community. Thank You!