+ Start a Discussion
병훈 송병훈 송 

How to know Field Type?

I want know Field Type.
LookUp or Master-Detail..

I want to make =  "I can't make bigger than two of Master-Detail Field."...

Map<String, Schema.SObjectField> typeMap = Schema.getGlobalDescribe().get(obj.name).getDescribe().fields.getMap();
        for(Schema.SObjectField ff : typeMap.values()) {
            Object typeO = ff.getDescribe().getType();
            typeTemp = String.valueOf(typeO);
            System.debug('typeO = ' + typeO);
            if(typeTemp == 'REFERENCE') {


Ajay K DubediAjay K Dubedi
Below Code can fulfill your requirements. Hope this will work for you.

Example : 1

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();

Example : 2
String objectName = 'Account';
String fieldName = 'Name';

SObjectType r = ((SObject)(Type.forName('Schema.'+objectName).newInstance())).getSObjectType();
DescribeSObjectResult d = r.getDescribe();
Please mark this as best answer if this solves your problem.

Thank you
Ajay Dubedi