Hi Himanshu,
For getting All Parent objects:
for(Schema.SobjectField strFld: Account.SobjectType.getDescribe().fields.getMap().Values()){
if(strFld.getDescribe().getType() == Schema.DisplayType.REFERENCE){
system.debug(‘==parent object=’+strFld.getDescribe().getReferenceTo());
}
}
For getting All Child objects:
Schema.DescribeSObjectResult R = Account.SObjectType.getDescribe();
for (Schema.ChildRelationship cr: R.getChildRelationships()) {
system.debug(‘====child object===’+cr.getChildSObject());
}
*Change Account as per your requirement.
Thanks