You need to sign in to do that
Don't have an account?
Buss
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
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
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.