+ Start a Discussion
m pandeym pandey 

parent to child records display ?

i need u r  help.....
https://developer.salesforce.com/forums/?id=906F0000000AxfCIAS 
as u have shown code for above link for  parent to child when we will select  for the parent to child
bt i need the select for all  where i check the check  all accounts should be selected and all contacts child should be shown in vf page....?
please let me get the code pleasee..
Best Answer chosen by m pandey
vishnu Rvishnu R
hi pandey,
try this code.....
 Apex Controller::
public class wrapper2 {
public list<wrapaccount> wrapaccountlist { get; set; }
public list<contact> selectedAccounts{get;set;}
public list<Id> accid{set;get;}
public list<contact> con{set;get;}  
public Wrapper2 (){      
      wrapaccountlist =new list<wrapaccount>();
      for(account a:[select id,name,billingcity,phone,(Select LastName,AccountId From Contacts) from account limit 10]){
       wrapaccountlist.add(new wrapaccount(a,false));   
       }
       system.debug('>>>>>>>>>>>>>'+ wrapaccountlist);
  }
  public void ProcessSelected(){
  selectedAccounts=new list<contact>();    
      accid= new list<Id>();
      con=new list<contact>();
   for(wrapaccount wrapobj: wrapaccountlist)
  {
   if(wrapobj.isSelected==true )
   {
    accid.add(wrapobj.accn.id);      
    }
   }
      con=[select LastName,AccountId from Contact where AccountId IN:accid];
      for(wrapaccount wrapobj:wrapaccountlist)
{
for(contact c:con)
{
if(c.AccountId==wrapobj.accn.Id)
{
if(wrapobj.isSelected==true ){  
selectedAccounts.add(c);
                  }
               }
          }
    }
 }
public class wrapaccount{    
public account accn{get;set;}
public boolean isSelected{get;set;}    
   public wrapaccount(account a,boolean c){    
     accn=a;
     isSelected=c;
   }
}
}


VF page::

<apex:page sidebar="false" controller="Wrapper2">
<apex:form >
 <apex:pageBlock >      
   <apex:pageBlockSection columns="2">
     <apex:pageBlockTable value="{!wrapaccountlist}" var="waccl" id="block1">                 
       <apex:column headerValue="Action" >                               
           <apex:inputCheckbox value="{!waccl.isSelected}">
          <apex:actionSupport event="onclick" action="{!ProcessSelected}" reRender="pt,block1" > 
           </apex:actionSupport>
           </apex:inputCheckbox>
       </apex:column>            
        <apex:column value="{!waccl.accn.name}"/>
        <apex:column value="{!waccl.accn.phone}"/>
        <apex:column value="{!waccl.accn.billingcity}"/>
     </apex:pageBlockTable>
     <apex:pageBlockSection columns="1" >
      <apex:pageBlockTable value="{!selectedAccounts}" id="pt" var="sa" >
        <apex:column value="{!sa.LastName}"/>
       </apex:pageBlockTable>
   </apex:pageBlockSection>
   </apex:pageBlockSection>
 </apex:pageBlock>
</apex:form>
</apex:page>
 

All Answers

vishnu Rvishnu R
hi pandey,
try this code.....
 Apex Controller::
public class wrapper2 {
public list<wrapaccount> wrapaccountlist { get; set; }
public list<contact> selectedAccounts{get;set;}
public list<Id> accid{set;get;}
public list<contact> con{set;get;}  
public Wrapper2 (){      
      wrapaccountlist =new list<wrapaccount>();
      for(account a:[select id,name,billingcity,phone,(Select LastName,AccountId From Contacts) from account limit 10]){
       wrapaccountlist.add(new wrapaccount(a,false));   
       }
       system.debug('>>>>>>>>>>>>>'+ wrapaccountlist);
  }
  public void ProcessSelected(){
  selectedAccounts=new list<contact>();    
      accid= new list<Id>();
      con=new list<contact>();
   for(wrapaccount wrapobj: wrapaccountlist)
  {
   if(wrapobj.isSelected==true )
   {
    accid.add(wrapobj.accn.id);      
    }
   }
      con=[select LastName,AccountId from Contact where AccountId IN:accid];
      for(wrapaccount wrapobj:wrapaccountlist)
{
for(contact c:con)
{
if(c.AccountId==wrapobj.accn.Id)
{
if(wrapobj.isSelected==true ){  
selectedAccounts.add(c);
                  }
               }
          }
    }
 }
public class wrapaccount{    
public account accn{get;set;}
public boolean isSelected{get;set;}    
   public wrapaccount(account a,boolean c){    
     accn=a;
     isSelected=c;
   }
}
}


VF page::

<apex:page sidebar="false" controller="Wrapper2">
<apex:form >
 <apex:pageBlock >      
   <apex:pageBlockSection columns="2">
     <apex:pageBlockTable value="{!wrapaccountlist}" var="waccl" id="block1">                 
       <apex:column headerValue="Action" >                               
           <apex:inputCheckbox value="{!waccl.isSelected}">
          <apex:actionSupport event="onclick" action="{!ProcessSelected}" reRender="pt,block1" > 
           </apex:actionSupport>
           </apex:inputCheckbox>
       </apex:column>            
        <apex:column value="{!waccl.accn.name}"/>
        <apex:column value="{!waccl.accn.phone}"/>
        <apex:column value="{!waccl.accn.billingcity}"/>
     </apex:pageBlockTable>
     <apex:pageBlockSection columns="1" >
      <apex:pageBlockTable value="{!selectedAccounts}" id="pt" var="sa" >
        <apex:column value="{!sa.LastName}"/>
       </apex:pageBlockTable>
   </apex:pageBlockSection>
   </apex:pageBlockSection>
 </apex:pageBlock>
</apex:form>
</apex:page>
 
This was selected as the best answer
sharathchandra thukkanisharathchandra thukkani
all the logic for this lies in the query

your query should be
List<Account> accList = [SELECT Name, (SELECT Name FROM Contacts) FROM Account];

 
m pandeym pandey
vishnu Ramireddy..............
Thnx for u r reply....
My requrirmenrt was to check all at a time so that instead of checking the check boxes one by one  when i select the checkall checkbox so that all parents(Account) need to be shown all childs(contact)..................





 
vishnu Rvishnu R
Hi pandey,

change the vf page like this.......and don't change the controller
Visualforce page::::::::::

<apex:page sidebar="false" controller="wrapper2">
<script>
        function checkAll(c)
        {
            var inputvar = document.getElementsByTagName("input");
            for(var i=0; i<inputvar.length; i++)
            {
                if(inputvar[i].id.indexOf("selec")!=-1)
                inputvar[i].checked = c.checked;
            }
        }
    </script>
<apex:form >
<apex:pageBlock >      
<apex:pageBlockSection columns="2">
 <apex:pageBlockTable value="{!wrapaccountlist}" var="waccl" id="block1">                 
   <apex:column >
   <apex:facet name="header">
   <apex:inputCheckbox >
   <apex:actionSupport event="onclick" action="{!ProcessSelected}" reRender="pt,block1" onsubmit="checkAll(this)"/>          
          </apex:inputCheckbox>             
           </apex:facet>                                          
       <apex:inputCheckbox value="{!waccl.isSelected}" id="selec">
      <apex:actionSupport event="onclick" action="{!ProcessSelected}" reRender="pt,block1"  />                      
       </apex:inputCheckbox>         
   </apex:column>            
    <apex:column value="{!waccl.accn.name}"/>
    <apex:column value="{!waccl.accn.phone}"/>
    <apex:column value="{!waccl.accn.billingcity}"/>
 </apex:pageBlockTable>
 <apex:pageBlockSection columns="1" >
  <apex:pageBlockTable value="{!selectedAccounts}" id="pt" var="sa" >
    <apex:column value="{!sa.LastName}"/>
   </apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>


Please let us know if this will help u

Thanks,
vishnu R
m pandeym pandey
account -  fld-Total sal-intger r currncy

contact -fld  -sal of cntct-intger r currncy

when ever we create cntct  and sal is added in the field all cntct sal of total should be updated in account total sal field

Task-ex: if we have 5 cntcts of sal(10.000,25.0000,55.444,22.000,77.0000) while creating f recrd and updatng the recrd in sal fld in cntcts
it should be total in accnt fild total sal.?
vishnu Rvishnu R
hi pandey,

can you start a new discussion for this .so that others can easily find the things abd it would be helpful to others..

thanks 
vishnu