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

Get the data type, not display type, of a field

I need to access the data types of the fields in an object in order to identify each phone, fax, email, and mail field in an object. I've done this from web services with the DescribeSObject call but the Apex DescribeFieldResult.getType method only return the display typeof the field, not the actual data type. For example, fields that display a Data Type of Fax like in the image below have a display type of Phone according the getType call. I need something that returns fax for fax fields, mail for mail fields, etc. like the DescribeSObject web service call. Does that exist in Apex?


Field Information


There isn't an email, fax, or phone datatype in Schema.DisplayType and I haven't figured out how to access them in Apex yet.  I believe these are just masked String types. 


Here are the ones you can use out of the box:


Type Field ValueWhat the Field Object Contains
anytypeAny value of the following types: String, Picklist, Boolean, Integer, Double, Percent, ID, Date,DateTime, URL, or Email.
base64Base64-encoded arbitrary binary data (of type base64Binary)
BooleanBoolean (true or false) values
ComboboxComboboxes, which provide a set of enumerated values and allow the user to specify a value not in the list
CurrencyCurrency values
DateDate values
DateTimeDateTime values
DoubleDouble values
EmailEmail addresses
EncryptedStringEncrypted string
IDPrimary key field for an object
IntegerInteger values
MultiPicklistMulti-select picklists, which provide a set of enumerated values from which multiple values can be selected
PercentPercent values
PhonePhone numbers. Values can include alphabetic characters. Client applications are responsible for phone number formatting.
PicklistSingle-select picklists, which provide a set of enumerated values from which only one value can be selected
ReferenceCross-references to a different object, analogous to a foreign key field
StringString values
TextAreaString values that are displayed as multiline text fields
TimeTime values
URLURL values that are displayed as hyperlinks