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
niharnihar 

create a visual force page by using apex class

Hi All,
My task is  to create a visual force page by using apex class. In visualforce page there should be only id field and search butoon 
and my requirment as follows
there are 6 objects obj1,obj2,obj3,obj4,obj5,obj6
in which obj1 has realtion with obj2 & obj2 has realtion with obj3
& obj3 has realtion with obj4 & obj4 has realtion with obj5 & obj5 has realtion with obj6
but when i paste an record id in the search box i must get the related lists of all 6objects in one page.............

Thanks inadvance..........
Best Answer chosen by nihar
Sampath SuranjiSampath Suranji
Hi ,
Try somthing like below,
VF page
<apex:page standardController="Obj1__C" extensions="displayChilds">
    <apex:form>
        <apex:pageBlock>
            <apex:inputText value="{!searchText}" />
            <apex:commandButton onclick="bindData('{!searchText}');return false;" value="Search" />
        </apex:pageBlock>
       
            <apex:dataTable value="{!Obj2List}" var="v" id="tblObj2" title="Obj2" rowClasses="odd,even" styleClass="tableClass">
                <apex:column title="Name"  >
                	<apex:facet name="header">Name</apex:facet>
                    <apex:outputText value="{!v.name}"/>
                </apex:column>
            </apex:dataTable>
            <br/>
            <apex:dataTable value="{!Obj3List}" var="v" id="tblObj3" title="Obj3">
                <apex:column title="Name"  >
                    <apex:facet name="header">Name</apex:facet>
                    <apex:outputText value="{!v.name}"/>
                </apex:column>
            </apex:dataTable>
            <br/>
            <apex:dataTable value="{!Obj4List}" var="v" id="tblObj4" title="Obj4">
                <apex:column title="Name" >
                    <apex:facet name="header">Name</apex:facet>
                    <apex:outputText value="{!v.name}"/>
                </apex:column>
            </apex:dataTable>
            <br/>
            <apex:dataTable value="{!Obj5List}" var="v" id="tblObj5" title="Obj5">
                <apex:column title="Name" >
                    <apex:facet name="header">Name</apex:facet>
                    <apex:outputText value="{!v.name}"/>
                </apex:column>
            </apex:dataTable>
            <br/>
            <apex:dataTable value="{!Obj6List}" var="v" id="tblObj6" title="Obj6">
                <apex:column title="Name">
                    <apex:facet name="header">Name</apex:facet>
                    <apex:outputText value="{!v.name}"/>
                </apex:column>
            </apex:dataTable>
        
        <apex:actionFunction id="bindData" name="bindData" action="{!bindData}" reRender="tblObj2,tblObj3,tblObj4,tblObj5,tblObj6">
            <apex:param name="obj1Value" value="" />
        </apex:actionFunction>
    </apex:form>
</apex:page>

Apex controlle
public class displayChilds {
    public obj1__c obj1{get;set;}
    public string searchText{get;set;}
    public List<Obj2__c> Obj2List{get;set;}
    public List<Obj3__c>Obj3List{get;set;}
    public List<Obj4__c>Obj4List{get;set;}
    public List<Obj5__c>Obj5List{get;set;}
    public List<Obj6__c>Obj6List{get;set;}
    
    public displayChilds(ApexPages.StandardController ctrl){
        // obj1 = (obj1__c)ctrl.getRecord();
    }
    
    public void bindData(){
        // string obj1Id = ApexPages.currentPage().getParameters().get('obj1Value');
        // searchText = obj1Id;
        System.debug('searchText '+searchText);
        bindObj2List();
    }
    public void bindObj2List(){
        if(searchText !=''){
            List<Obj1__c> ObjList = [select id,  Obj2__r.Id,Obj2__r.Name from obj1__C where id =:searchText  ];
            Obj2List = new List<Obj2__c>();
            for(obj1__C c: ObjList){
                if(c.Obj2__r!=null){                    
                    Obj2List.add(c.Obj2__r); 
                }
            }
            if(Obj2List.size()>0){
                bindObj3List();
            }
        }	        
        
    }
    public void bindObj3List(){
        
        List<ID>objExistId= new List<Id>();
        for(Obj2__c c:Obj2List ){
            objExistId.add(c.id);
        } 
        List<Obj2__c> ObjList = [select id,  Obj3__r.Id,Obj3__r.Name from obj2__C where Id  in :objExistId  ];
        System.debug('ObjList '+ObjList);
        Obj3List = new List<Obj3__c>();
        for(obj2__C c: ObjList){ 
            if(c.Obj3__r!=null){            	
                Obj3List.add(c.Obj3__r);  
            }
        }        	        
        if(Obj3List.size()>0){
            bindObj4List();
        }
    }
    public void bindObj4List(){
        
        List<ID>objExistId= new List<Id>();
        for(Obj3__c c:Obj3List ){
            objExistId.add(c.id);
        } 
        List<Obj3__c> ObjList = [select id,  Obj4__r.Id,Obj4__r.Name from obj3__C where Id  in :objExistId  ];
        Obj4List = new List<Obj4__c>();
        for(obj3__C c: ObjList){ 
            if(c.Obj4__r!=null){ 
                system.debug('c'+c);
                Obj4List.add(c.Obj4__r);
            }
            
        } 
        if(Obj4List.size()>0){
            bindObj5List();
        }
        
    }
    public void bindObj5List(){
        
        List<ID>objExistId= new List<Id>();
        for(Obj4__c c:Obj4List ){
            objExistId.add(c.id);
        } 
        List<Obj4__c> ObjList = [select id,  Obj5__r.Id,Obj5__r.Name from obj4__C where Id  in :objExistId  ];
        Obj5List = new List<Obj5__c>();
        
        for(obj4__C c: ObjList){ 
            if(c!=null){
                Obj5List.add(c.Obj5__r);
            }
        } 
        if(Obj5List.size()>0){
            bindObj6List();
        }
        
    }
    public void bindObj6List(){
        
        List<ID>objExistId= new List<Id>();
        for(Obj5__c c:Obj5List ){
            objExistId.add(c.id);
        } 
        List<Obj5__c> ObjList = [select id,  Obj6__r.Id,Obj6__r.Name from obj5__C where Id  in :objExistId  ];
        for(obj5__C o1: ObjList){               
            Obj6List = new List<Obj6__c>();
            Obj6List.add(o1.Obj6__r);            	
        } 
        
        
    }
    
}

it is starting searching from obj1__c

regards

All Answers

Sampath SuranjiSampath Suranji
Hi ,
Try somthing like below,
VF page
<apex:page standardController="Obj1__C" extensions="displayChilds">
    <apex:form>
        <apex:pageBlock>
            <apex:inputText value="{!searchText}" />
            <apex:commandButton onclick="bindData('{!searchText}');return false;" value="Search" />
        </apex:pageBlock>
       
            <apex:dataTable value="{!Obj2List}" var="v" id="tblObj2" title="Obj2" rowClasses="odd,even" styleClass="tableClass">
                <apex:column title="Name"  >
                	<apex:facet name="header">Name</apex:facet>
                    <apex:outputText value="{!v.name}"/>
                </apex:column>
            </apex:dataTable>
            <br/>
            <apex:dataTable value="{!Obj3List}" var="v" id="tblObj3" title="Obj3">
                <apex:column title="Name"  >
                    <apex:facet name="header">Name</apex:facet>
                    <apex:outputText value="{!v.name}"/>
                </apex:column>
            </apex:dataTable>
            <br/>
            <apex:dataTable value="{!Obj4List}" var="v" id="tblObj4" title="Obj4">
                <apex:column title="Name" >
                    <apex:facet name="header">Name</apex:facet>
                    <apex:outputText value="{!v.name}"/>
                </apex:column>
            </apex:dataTable>
            <br/>
            <apex:dataTable value="{!Obj5List}" var="v" id="tblObj5" title="Obj5">
                <apex:column title="Name" >
                    <apex:facet name="header">Name</apex:facet>
                    <apex:outputText value="{!v.name}"/>
                </apex:column>
            </apex:dataTable>
            <br/>
            <apex:dataTable value="{!Obj6List}" var="v" id="tblObj6" title="Obj6">
                <apex:column title="Name">
                    <apex:facet name="header">Name</apex:facet>
                    <apex:outputText value="{!v.name}"/>
                </apex:column>
            </apex:dataTable>
        
        <apex:actionFunction id="bindData" name="bindData" action="{!bindData}" reRender="tblObj2,tblObj3,tblObj4,tblObj5,tblObj6">
            <apex:param name="obj1Value" value="" />
        </apex:actionFunction>
    </apex:form>
</apex:page>

Apex controlle
public class displayChilds {
    public obj1__c obj1{get;set;}
    public string searchText{get;set;}
    public List<Obj2__c> Obj2List{get;set;}
    public List<Obj3__c>Obj3List{get;set;}
    public List<Obj4__c>Obj4List{get;set;}
    public List<Obj5__c>Obj5List{get;set;}
    public List<Obj6__c>Obj6List{get;set;}
    
    public displayChilds(ApexPages.StandardController ctrl){
        // obj1 = (obj1__c)ctrl.getRecord();
    }
    
    public void bindData(){
        // string obj1Id = ApexPages.currentPage().getParameters().get('obj1Value');
        // searchText = obj1Id;
        System.debug('searchText '+searchText);
        bindObj2List();
    }
    public void bindObj2List(){
        if(searchText !=''){
            List<Obj1__c> ObjList = [select id,  Obj2__r.Id,Obj2__r.Name from obj1__C where id =:searchText  ];
            Obj2List = new List<Obj2__c>();
            for(obj1__C c: ObjList){
                if(c.Obj2__r!=null){                    
                    Obj2List.add(c.Obj2__r); 
                }
            }
            if(Obj2List.size()>0){
                bindObj3List();
            }
        }	        
        
    }
    public void bindObj3List(){
        
        List<ID>objExistId= new List<Id>();
        for(Obj2__c c:Obj2List ){
            objExistId.add(c.id);
        } 
        List<Obj2__c> ObjList = [select id,  Obj3__r.Id,Obj3__r.Name from obj2__C where Id  in :objExistId  ];
        System.debug('ObjList '+ObjList);
        Obj3List = new List<Obj3__c>();
        for(obj2__C c: ObjList){ 
            if(c.Obj3__r!=null){            	
                Obj3List.add(c.Obj3__r);  
            }
        }        	        
        if(Obj3List.size()>0){
            bindObj4List();
        }
    }
    public void bindObj4List(){
        
        List<ID>objExistId= new List<Id>();
        for(Obj3__c c:Obj3List ){
            objExistId.add(c.id);
        } 
        List<Obj3__c> ObjList = [select id,  Obj4__r.Id,Obj4__r.Name from obj3__C where Id  in :objExistId  ];
        Obj4List = new List<Obj4__c>();
        for(obj3__C c: ObjList){ 
            if(c.Obj4__r!=null){ 
                system.debug('c'+c);
                Obj4List.add(c.Obj4__r);
            }
            
        } 
        if(Obj4List.size()>0){
            bindObj5List();
        }
        
    }
    public void bindObj5List(){
        
        List<ID>objExistId= new List<Id>();
        for(Obj4__c c:Obj4List ){
            objExistId.add(c.id);
        } 
        List<Obj4__c> ObjList = [select id,  Obj5__r.Id,Obj5__r.Name from obj4__C where Id  in :objExistId  ];
        Obj5List = new List<Obj5__c>();
        
        for(obj4__C c: ObjList){ 
            if(c!=null){
                Obj5List.add(c.Obj5__r);
            }
        } 
        if(Obj5List.size()>0){
            bindObj6List();
        }
        
    }
    public void bindObj6List(){
        
        List<ID>objExistId= new List<Id>();
        for(Obj5__c c:Obj5List ){
            objExistId.add(c.id);
        } 
        List<Obj5__c> ObjList = [select id,  Obj6__r.Id,Obj6__r.Name from obj5__C where Id  in :objExistId  ];
        for(obj5__C o1: ObjList){               
            Obj6List = new List<Obj6__c>();
            Obj6List.add(o1.Obj6__r);            	
        } 
        
        
    }
    
}

it is starting searching from obj1__c

regards
This was selected as the best answer
niharnihar
hi Sampath Suranji,

Thanks for your but i need some changes in the code.........
when i click on obj1 it is showing obj2,obj3,obj4,obj5,obj6

but i also want 
when i click on obj2 it must show obj1,obj3,obj4,obj5,obj6
when i click on obj3 it must show obj1,obj2,obj4,obj5,obj6
when i click on obj4 it must showobj1,obj2,obj3,obj5,obj6
when i click on obj5 it must show obj1,obj2,obj3,obj4,obj6
when i click on obj6 it must show obj1,obj2,obj3,obj4,obj5