+ Start a Discussion
georggeorg 

get Object data type in apex class

Hi All,

 

 

Please help me...

 

For one of my apex class i need to fill out some mandatory fields with dummy data. Actually i want to get the field data type in apex class to fill dummy data. How i can do this.

Best Answer chosen by Admin (Salesforce Developers) 
ryanjuptonryanjupton

You can get a field's data type with something like this (I've used an Account field in this example)

 

Schema.DisplayType dt = Schema.sObjectType.Account.fields.AnnualRevenue.getType();
System.debug('***** Type ' + dt.name() +' *****');

 

The result here is Currency. Your question was kind of vague so it's possible I missed it's intent. if so feel free to clarify.