public class objectLists{
    public String SeletedObject {get; set;}
    public  String childObj {get;set;}
    List<SelectOption> options;

    public List<SelectOption> getObjectOptions() 
         options = new List<SelectOption>();
         Map<String, Schema.SObjectType> AllObjmap   = New Map<String, Schema.SObjectType>();
         AllObjmap = Schema.getGlobalDescribe();

         System.debug('******All object Names******* :'+ AllObjmap.keyset());

         for(String ObjectName: AllObjmap.keySet())
            List<string> objlist = new List<string>();
            options.add(new SelectOption(ObjectName,ObjectName));

        return options;        
    public void getrelatedchild()
         Map<string,string> childMap = new Map<String, String>();
         List<Schema.Childrelationship> childList = Schema.getGlobalDescribe().get(SeletedObject).getdescribe().getChildRelationships();

vf page

<apex:page controller="objectLists" >
    <apex:form >
        <apex:pageBlock title="Select Object">

           <apex:actionFunction name="getchild" action="{!getrelatedchild}" oncomplete="alert('compeleted')" />

            <apex:outputPanel >Object:</apex:outputPanel>

              <apex:selectList size="1" value="{!SeletedObject}" onchange="callchild();">
                    <apex:selectOptions value="{!ObjectOptions}" />

           <apex:pageBlockTable value="{!childObj}" columns="2" var="item" id="a">



I'm creating picklist of Standard and custom objects, after selecting specific object I want to display related records to that object in pageblocktable. I'm able to add the objects in picklist but unable to disply related records in pageblocktable

1 Answer 1


You certainly can't specify a return type of void. Just return the List<ChildRelationship> and be done with the Apex involved. Here's a demo with just the ChildRelationship table:


public with sharing class Demo
    public List<ChildRelationship> getRelationships()
        return SObjectType.MyObject__c.getChildRelationships();


<apex:page controller="Demo">
        <apex:pageBlockTable value="{!relationships}" var="relation">
            <apex:column value="{!relation.childSObject}" />
            <apex:column value="{!relation.field}" />
            <apex:column value="{!relation.relationshipName}" />

Interestingly, it seems like you ought to be able to use {!$ObjectType.MyObject__c.childRelationships} where I have {!relationships} and get rid of Apex altogether, but it does not seem to be supported.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.