[SalesForce] Lookup Field Object

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

"fieldsMap.get(field).getDescribe().getType()+''=='REFERENCE'"

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

Best Answer

I think you can do something like this:

Schema.DescribeFieldResult f = fieldsMap.get(field).getDescribe();   
System.debug(f.getRelationshipName())    
for(Schema.SObjectType reference : f.getReferenceTo())
{
    System.debug(reference.getDescribe().getName());
}

See docs here for more info.