", "answerCount": 3, "upvoteCount": 0, "datePublished": "2020-03-30T02:33:25.000Z", "author": { "@type": "Person", "name": "Yeturu Srikanth", "url": "https://trailblazers.salesforce.com/profileView?u=0053A00000E7UCRQA3", "affiliation": { "@type": "Organization", "name": "bigworks" } }, "suggestedAnswer": [ { "@type": "Answer", "text": "Hi Srikanth, you can use 2 separate lists one for displaying account section and other for displaying account and its related contacts. see the code inĀ  https://salesforceglobe4u.blogspot.com/2020/03/how-to-display-account-and-its-related.html Thanks", "upvoteCount": 0, "url": "https://trailhead.salesforce.com/trailblazer-community/feed/0D54V00007T4IopSAF", "datePublished": "2020-03-30T07:26:50.000Z", "author": { "@type": "Person", "name": "Kumar Suneel", "url": "https://trailblazers.salesforce.com/profileView?u=00530000008BW5ZAAW", "affiliation": { "@type": "Organization", "name": "ABC" } } } ] } } Skip to main content
 Right side block should display Account name as a heading and its related contacts under that account make those changes.

 page block 2 is not working ...?

// class

public class AccountSelectClassController {

    public list<wrapaccount> wrapaccountList { get; set; }

    public list<account> selectedAccounts{get;set;}     

    public list<id> selectedrecordsIds{get;set;}

    public list<Contact> records{get;set;}

    public list<Account> names{get;set;}

    public AccountSelectClassController ()

    {

      

       if(wrapaccountList ==null)

            {

                 wrapaccountList =new list<wrapaccount>();

                 for(account a:[select id,name from account limit 10])

                 {

                 wrapaccountlist.add(new wrapaccount(a));

        

                  }

            }

     }

    

     public void ProcessSelected()

     {

       selectedAccounts=new list<account>();

       selectedrecordsIds =new list<id>();

       records =new List<Contact>();

       names =new List<Account>();

       for(wrapaccount wrapobj:wrapaccountlist)

          {

              if(wrapobj.isSelected==true)

                {

                   selectedAccounts.add(wrapobj.accn);

                }   

          }

          

          for(Account abc:selectedAccounts)

          {

            selectedrecordsIds.add(abc.id);   

          }

                names = [SELECT Name,label__c FROM ACCOUNT WHERE Id IN :selectedrecordsIds];

         

             records = [SELECT Name FROM Contact WHERE AccountId IN : selectedrecordsIds];

               

             System.debug('bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'+records);

          System.debug('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'+selectedrecordsIds);

            System.debug('ccccccccccccccccccccccccccccccccccccccc'+names);

      }

      

  

   

   public class wrapaccount

   {

    

    public account accn{get;set;}

    public boolean isSelected{get;set;}

     

       public wrapaccount(account a)

       {

     

         accn=a;

         isselected=false;

       }

   }

}

vf pafe :-

<apex:page sidebar="false" controller="AccountSelectClassController">

    

    

    <script type="text/javascript">

        function selectAllCheckboxes(obj,receivedInputID){

            var inputCheckBox = document.getElementsByTagName("input");

            for(var i=0; i<inputCheckBox.length; i++){

                if(inputCheckBox[i].id.indexOf(receivedInputID)!=-1){

                    inputCheckBox[i].checked = obj.checked;

                }

            }

        }

    

    </script>

 <apex:form >

    

     <apex:pageBlock id="block2">

       

       <apex:pageBlockSection columns="2">

         <apex:pageBlockTable value="{!wrapaccountList}" var="waccl">

            

           <apex:column >

              <apex:facet name="header">

                            <apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId')"/>

                        </apex:facet>

            <apex:inputCheckbox value="{!waccl.isSelected}" id="InputId"/>

           </apex:column>

            

            <apex:column value="{!waccl.accn.name}"/>

         </apex:pageBlockTable>

           <apex:pageBlock >

           

   

          <apex:pageBlockTable value="{!names}" var="aaa">

             <apex:column value="{!aaa.Name}" headerValue="name"/>

                                

               

              <apex:pageBlockTable value="{!records}" var="qqq">

                  <apex:column value="{!qqq.name}"/>

              </apex:pageBlockTable>

              </apex:pageBlockTable>

           </apex:pageBlock>

       </apex:pageBlockSection>

         

         <apex:pageBlockButtons location="bottom">

          <apex:commandButton action="{!ProcessSelected}" value="Show Selected Contacts" reRender="block2"/>

        </apex:pageBlockButtons>

         

     </apex:pageBlock>

    

   </apex:form>

</apex:page>

 
3 answers
0/9000