+ Start a Discussion
Ridhima Saxena 21Ridhima Saxena 21 

How to filter only number fields in apex ??

Hiii Developer,
I have created sum picklist in LWC and i wanted to show only number field if i select sum from the picklist so it should show number fields not all the fields.
Help me to give solution in apex.
How to filter number field in apex??

Thanks in advance
ANUTEJANUTEJ (Salesforce Developers) 
Hi Ridhima,

I see that there is a class called Type that has a method called getType that you can use to get the type of the field.

Below is the snipet of code of apex that I found:
Link: https://developer.salesforce.com/forums/?id=906F0000000914l
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 it helps you and close your query by marking it as solved so that it can help others in the future.  

Instead of using APEX, you may use uiObjectInfoApi. You may use this to get object metadata and picklist values. Refer the below URL for details:


We have used this for a project and it's much faster than going to server(i.e. through APEX).