Skip to main content
10 respostas
  1. 8 de ago. de 2018, 11:44
    Hi Prema,

    you can use the below schema class to get the child objects details based on parent:

    just execute the below class in the debug you can see the list of childs:

    Schema.DescribeSObjectResult R = Contact.SObjectType.getDescribe();    ///// use the any object instead of contact here

    List<Schema.ChildRelationship> C = R.getChildRelationships(); 

    integer i = 1;

    for(Schema.ChildRelationship rel:C){

       if (rel.getChildSObject().getDescribe().fields.getMap().get('Name') != null)

    {

        System.debug(i + '  @@@ Child Name  '+rel.getChildSObject());    

        // System.debug(i + '  @@@ Rel Name  '+rel.getRelationshipName());  

        i++; 

    }     

        

    }

    https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_class_Schema_ChildRelationship.htm⌗apex_Schema_ChildRelationship_methods

    http://sfdcsrini.blogspot.com/2015/05/schemadescribesobjectresult-in-apex-and.html

    https://salesforce.stackexchange.com/questions/119832/get-the-specified-child-relationship-name-from-parent

    http://salesforce-walker.blogspot.com/2012/12/getting-child-relationshipnames-using.html

    Can you please Let me know if it helps or not!!!

    If it helps don't forget to mark this as a best answer!!!

    Thanks,

    Raj