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
John L.John L. 

Specifying type for Map<String,Schema.SObjectField>

I'm building a Map for a user table. I know the attribute names, what do I specify for Schema.SObjectField data types?

The particular types of interest are "Auto Number" and "Date/Time".

Thanks in advance for any insight you may provide.
Suraj Tripathi 47Suraj Tripathi 47

Hi John,

Please find the solution. "Specifying type for Map<String,Schema.SObjectField>".

You can take reference from this code by using system.debug();

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
 

         }

I hope it will help you.

Please mark it as Best Answer so that other people would take reference from it.

Thank You!

John L.John L.
Map<String, Schema.SObjectType> gd =             System.Schema.getGlobalDescribe();           System.debug(Logginglevel.INFO,'ks='+gd.keyset().isEmpty()+         ' '+gd.keyset().toString());

is empty set. Can't seem to crawl.
John L.John L.
Also

Map<String,Schema.SObjectField> Map = Schema.SObjectType.<table>.fields.getMap();

fails with null map keyset;
Suraj Tripathi 47Suraj Tripathi 47
would you like to share your code