Assume Opportunity is the current object, you want to know all parent object and child objects info of the current object.
All Parent Objects
Sample Code
for(Schema.SobjectField iterator: Opportunity.SobjectType.getDescribe().fields.getMap().Values()) {
if(iterator.getDescribe().getType() == Schema.DisplayType.REFERENCE) {
system.debug('Parent Objects ====> '+iterator.getDescribe().getReferenceTo());
}
}
Sample Code
Schema.DescribeSObjectResult sObjectInfo = Opportunity.SObjectType.getDescribe();
for (Schema.ChildRelationship iterator: sObjectInfo.getChildRelationships()) {
system.debug('Child Objects ====> '+iterator.getChildSObject());
}