I have to get the object name of the lookup field in any object. I am using:

sobjectType objectType=Schema.getGlobalDescribe().get('SA_S3_File__c').

then, to get the lookup field name, i am using


after getting the fieldname of lookup, how can i get the object name of those lookup fields?

2 Answers 2


I think you can do something like this:

Schema.DescribeFieldResult f = fieldsMap.get(field).getDescribe();   
for(Schema.SObjectType reference : f.getReferenceTo())

See docs here for more info.


Same as Phil Hawthorn's answer but with a loop and you can just "toString" an SObjectType to get its name, no need for another describe:

SObjectType t = ...;

DescribeSObjectResult dt = t.getDescribe();
for (SObjectField f : dt.fields.getMap().values()) {
    DescribeFieldResult df = f.getDescribe();
    if (df.getType() == DisplayType.Reference) {
        for (SObjectType r : df.getReferenceTo()) {
            System.debug('field ' + df.getName() + ' references type ' + r);

Normally the getReferenceTo only returns one type.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .