Fetch all Parent objects API names:
for(Schema.SobjectField fldMap: Account.SobjectType.getDescribe().fields.getMap().Values())
{
if(fldMap.getDescribe().getType() == Schema.DisplayType.REFERENCE)
{
system.debug('Parent object Api names=====>' +fldMap.getDescribe().getReferenceTo());
}
}
Fetch all Child objects API names:
Schema.DescribeSObjectResult R = Account.SObjectType.getDescribe();
for (Schema.ChildRelationship childrelationship: R.getChildRelationships())
{
system.debug('child object API names===>' +childrelationship.getChildSObject());
}
change on API Name Account with your required object API name.
for(Schema.SobjectField fldMap: Account.SobjectType.getDescribe().fields.getMap().Values())
{
if(fldMap.getDescribe().getType() == Schema.DisplayType.REFERENCE)
{
system.debug('Parent object Api names=====>' +fldMap.getDescribe().getReferenceTo());
}
}
Fetch all Child objects API names:
Schema.DescribeSObjectResult R = Account.SObjectType.getDescribe();
for (Schema.ChildRelationship childrelationship: R.getChildRelationships())
{
system.debug('child object API names===>' +childrelationship.getChildSObject());
}
change on API Name Account with your required object API name.
No Comment to " How to get all Parent and child objects related to the current object "