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
StenEStenE 

Get FieldType with dynamix apex

Hi Everyone,

 

I'm stuck.

 

I have an Sobject (contact,account or lead) and it's quite easy to get the data out of it.

 

SObject obj;
String Input = string.valueof(obj.get('Phone'));

 

 But now i need to know the field type as well. I thought it would be something like this. Please help.

 

Schema.SObjectField Fld = (Schema.sObjectField) obj.get('Phone');
Schema.DisplayType FldType = Fld.getDescribe().getType();

 

Thanks already!

 

Sten

 

 

Best Answer chosen by Admin (Salesforce Developers) 
StenEStenE

Ok.  Did it like this.

 

Map<String, Schema.SObjectField> M;
if (TypeObject=='Account') M = Schema.SObjectType.Account.fields.getMap();
Schema.SObjectField field = M.get('Fax');
Schema.DisplayType FldType = field.getDescribe().getType();

 This works for me.

 

Thanks.

All Answers

AmitSahuAmitSahu

Can you try ?

 

Schema.DescribeFieldResult F = Schema.SObjectType.Account.fields.Name;
System.Debug('Value of F'+ F.getType());

 You can dynamically replace the field name.

 

Regards,

 

 

StenEStenE

Ok.  Did it like this.

 

Map<String, Schema.SObjectField> M;
if (TypeObject=='Account') M = Schema.SObjectType.Account.fields.getMap();
Schema.SObjectField field = M.get('Fax');
Schema.DisplayType FldType = field.getDescribe().getType();

 This works for me.

 

Thanks.

This was selected as the best answer