How to get field data types for each fields in Salesforce objects?

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:

Type Field Value What the Field Object Contains
anytype Any value of the following types: StringPicklistBooleanIntegerDoublePercentIDDateDateTimeURL, orEmail.
base64 Base64-encoded arbitrary binary data (of type base64Binary)
Boolean Boolean (true or false) values
Combobox Comboboxes, which provide a set of enumerated values and allow the user to specify a value not in the list
Currency Currency values
DataCategoryGroupReference Reference to a data category group or a category unique name.
Date Date values
DateTime DateTime values
Double Double values
Email Email addresses
EncryptedString Encrypted string
ID Primary key field for an object
Integer Integer values
MultiPicklist Multi-select picklists, which provide a set of enumerated values from which multiple values can be selected
Percent Percent values
Phone Phone numbers. Values can include alphabetic characters. Client applications are responsible for phone number formatting.
Picklist Single-select picklists, which provide a set of enumerated values from which only one value can be selected
Reference Cross-references to a different object, analogous to a foreign key field
String String values
TextArea String values that are displayed as multiline text fields
Time Time values
URL URL values that are displayed as hyperlinks

Written by 

I am Sakthivel Madesh, a certified Salesforce Advanced Developer & Administrator working on Salesforce Technology since 2011. I am currently working in Techforce Services as Sr. Salesforce Developer. I have worked on multiple technologies Like PHP, Java, Salesforce, I am very passionate about Salesforce and to earn 15x Salesforce Certification. I love Trailhead for learning Salesforce Skill and Become a Trailhead 6x Ranger too. I Love to Learn & Share my Salesforce knowledge to Salesforce Learners/Beginner using My Blog and Salesforce Community.

Leave a Reply

Your email address will not be published. Required fields are marked *