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
BussBuss 

can Reflection on Object Fields possible?

Hi Friends,

I have one object record(Contact record) which has some Phone Fields, here I would like to check fetched Contact record field type as Phone. If true then I wish to access corresponding phone field values. Please can any one help on this issue?


Thanks,
Buss
Elie.RodrigueElie.Rodrigue
I'm not quite sure I fully get what you want to achieve, however here's some pointers to help you out : 
you can get any field value from an sObject using the get method. So you could have this kind of code : 

string fieldName = 'HomePhone';
Contact c= [Select Id, HomePhone, MobilePhone... from Contact where ... limit 1];
string fieldValue = (string)c.get(fieldName);

You could also figure out if a given field is a phone field using the describes method.
Map<String, Schema.SObjectField> M = Schema.SObjectType.Contact.fields.getMap();
if(M.get(fieldName).getDescribe().getType()  == Schema.DisplayType.Phone) { /*process*/ }

You could also iterate through each field in the M map.