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
RavitejaRaviteja 

datatable with account and parent account

i have datatable with columns

             1.account name    2.childs of account    

                    ---                                 ---

                    ---                                  ---


in first column all account names and secound column should consists child record names(parent account)

i am unable to write soql query to retrieve child records

 

 i wrote below code:

 

vf:

================================

<apex:page standardController="account" sidebar="false" recordSetVar="acc" extensions="getchilds">
    <apex:form >
        <apex:pageBlock >
            <apex:dataTable bgcolor="silver" border="2" value="{!acc}" var="a" cellspacing="10" cellpadding="5">
             <apex:facet name="header">List of account along with childs</apex:facet>
        <apex:column >
                <apex:facet name="header">parent</apex:facet>           
            <apex:outputText value="{!a.name}"/>
        </apex:column>
        <apex:column >
                <apex:facet name="header">childs</apex:facet>          
            <apex:outputText />
        </apex:column>
        <apex:column >
                <apex:facet name="header">phone</apex:facet>          
            <apex:outputText value="{!a.phone}"/>
        </apex:column>
                
            </apex:dataTable>
        </apex:pageBlock>
    </apex:form>
 </apex:page>

 

class:

==============

public class getchilds {
list<string> child=new list<string>();
    
    public getchilds(ApexPages.StandardSetController controller) {
        child=[select name from account where id=parentid];
    }

}

asish1989asish1989

Hi

    Try this 

         

public class getchilds {
list<Account> child=new list<Account>();

public getchilds(ApexPages.StandardSetController controller) {
child=[select name ,ParentId from account where ParentId !=null];
System.debug('############Child records##########'+child.size());
}

}

 

you can check in your debuglog about number of child account records . 

 

Did this post answers your issue if so please mark it solved

 

Thanks

asish