function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
AnushaAnusha 

Re : How to get the Chiled Object Name

Hello evryone,

 

i have a small issue that,

One of my reqirement is, I'm passing a Recod Id from page to Class using param, now using that record Id I need to find the Child Relations on the Object.

Please help me........................

Devendra NataniDevendra Natani

Do you want to fetch the child objects of a sobject?

AnushaAnusha

Yeah,

If know that, please tell me

CLKCLK

use below generic fuction to get list of Fields who has child Relationships with specified sobject type.

 

List<Schema.SObjectField> getChildRelationshipsFields(Schema.sObjectType objType)
{
    String strResult = null;

    //Sobjetct obj = new Account();
    //Schema.sObjectType objType = obj.getSObjectType();
    Schema.DescribeSObjectResult ObjResult =  objType.getDescribe();
    getChildRelationships List<Schema.ChildRelationship> lstChild = ObjResult.getChildRelationships();
    List<Schema.SObjectField> lstFields = new List<Schema.SObjectField>();
    for(Schema.ChildRelationship objChild : lstChild)
        lstFields.add(objChild.getField())
    return lstFields;
}

Devendra NataniDevendra Natani

 

Map<String,Schema.SObjectType> gd = Schema.getGlobalDescribe();
Schema.SObjectType sObjType  = gd.get('account');
Schema.DescribeSObjectResult sObjResult =  sObjType.getDescribe();
List<Schema.ChildRelationship> lstChildR = sObjResult.getChildRelationships();
  
    for(Schema.ChildRelationship cr : lstChildR )
        system.debug('@@@@'+cr.getChildSObject());

 

Please try the above code the get child objects.