Activity Forums Salesforce® Discussions Get all Parent and child objects related to the current object

  • Surbhi

    Member
    May 25, 2016 at 1:17 pm

    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

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos