String parentObj = 'Account';
String childObj = 'Contact';
Map<String,Schema.SObjectField> fieldMap = Schema.getGlobalDescribe().get(childObj).getDescribe().fields.getMap();
for(Schema.SObjectField f:fieldMap.values()){
String type = String.valueOf(f.getDescribe().getReferenceTo());
if(type.contains(parentObj)){
system.debug('Field Name:- ' + f.getDescribe().getName());
}
}
String childObj = 'Contact';
Map<String,Schema.SObjectField> fieldMap = Schema.getGlobalDescribe().get(childObj).getDescribe().fields.getMap();
for(Schema.SObjectField f:fieldMap.values()){
String type = String.valueOf(f.getDescribe().getReferenceTo());
if(type.contains(parentObj)){
system.debug('Field Name:- ' + f.getDescribe().getName());
}
}