I want to get dynamically all field for object (assume for Account) which are User reference . Using the describe method I can check that the field is Reference type but not clear how/if can I check the sobject type that is being referenced.
map <String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
for(Schema.SObjectField field : schemaMap.get('Account').getDescribe().fields.getMap().values()){
Schema.DescribeFieldResult dr = field.getDescribe();
if(dr.getType() == DisplayType.Reference){
System.debug(dr.getName());
}
}