• How to get all Parent and child objects related to the current object

    Published By: salesforcepoint
    Published: Sunday, 11 February 2018
    A- A+
    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.

    Subjects:

  • No Comment to " How to get all Parent and child objects related to the current object "