Problem : I know sobject name and field api name as well.Now I want to know the datatype of this field dynamically in apex
Solution:
For example :
String sObjName ='contact';
String fieldName = 'Birthdate';
Schema.DisplayType fielddataType = Schema.getGlobalDescribe().get(sObjName).getDescribe().fields.getMap().get(fieldName).getDescribe().getType();
system.debug('fielddataType fielddataType '+fielddataType );
if(fielddataType == Schema.DisplayType.Date) {
System.debug('Birthdate Field DataType is : Date');
}
Output :
Solution:
For example :
String sObjName ='contact';
String fieldName = 'Birthdate';
Schema.DisplayType fielddataType = Schema.getGlobalDescribe().get(sObjName).getDescribe().fields.getMap().get(fieldName).getDescribe().getType();
system.debug('fielddataType fielddataType '+fielddataType );
if(fielddataType == Schema.DisplayType.Date) {
System.debug('Birthdate Field DataType is : Date');
}
Output :
No comments:
Post a Comment