+ Start a Discussion
ryyhryyh 

Determine data type from "Object"

If i have a generic object returned from a function is there a APEX function to determine the type (Boolean, String, List, Set, etc) from the function?

Best Answer chosen by Admin (Salesforce Developers) 
jadentifyjadentify

you use the instanceof keyword such as:

 

 

String s = 'Hello';
Object o = s;
If ( o instanceof String ) {}

 

 

 

you can use this for primitive data types as well as classes

All Answers

Rahul SharmaRahul Sharma

There are describe methods by which you can get all the details.

Example:

system.debug('Datatype of Name is : '+Account.Name.getDescribe().getType());

 For more view : Describe Method Details

jadentifyjadentify

you use the instanceof keyword such as:

 

 

String s = 'Hello';
Object o = s;
If ( o instanceof String ) {}

 

 

 

you can use this for primitive data types as well as classes

This was selected as the best answer