• vara prasad 4
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
User-added image
Hi all,
please let me know,how to get all contacts of an account on click on count of contact as show above screenshort.
please let me know what i missing in below code

apex class...........

public with sharing class sampleCode {

public List<wrapper> wrapperList{get; set;}
public List<Contact> contactsInformation { get; set; }
public Id selectedCountOfContact { get; set; }


public sampleCode(){
         wrapperList=new List<Wrapper>();
         for(Account a:[select Name,(select id,name from contacts),(select id from opportunities)  from Account limit 5])
         {
           Wrapper w1=new Wrapper();
           w1.Name=a.Name;
           w1.Con=a.contacts.size();
              
           w1.Opp=a.opportunities.size();
           wrapperList.add(w1);
         }       
}

class Wrapper{
    public String Name{get; set;}
    public Integer Con{get; set;}
    public Integer Opp{get; set;}   
 }
 
public List<Account> getMyAccounts() {
return [SELECT Id, Name,Industry, AccountNumber FROM Account ORDER BY
LastModifiedDate DESC LIMIT 10];
}

public void accountClicked() {
contactsInformation = [SELECT FirstName, LastName FROM Contact
WHERE AccountID = :selectedCountOfContact];
  }
}


and page.........



<apex:page controller="sampleCode">

<apex:form >

<apex:outputPanel id="ContactDetail">

<apex:repeat value="{!contactsInformation}" var="contact">
<p>{! contact.FirstName & ' ' & contact.LastName}</p>
</apex:repeat>
</apex:outputPanel>

<apex:pageBlock >
     <apex:pageBlockTable value="{!wrapperList}" var="b" >
                         <apex:column value="{!b.Name}" headerValue="Account Name"/>
                   
                         <apex:column headerValue="Total Contacts">  
                             <apex:commandlink action="{!accountClicked}" rerender="ContactDetail">
                             <apex:outputText value="{! b.con}"/>
                             <!--  <apex:param name="id" value="{!b.id}" assignTo="{!selectedcountofcontact}"/>-->
                         </apex:commandLink>                             
                         </apex:column>
                         
                         <apex:column headerValue="Total Opportunities">
                             <apex:commandLink value="{!b.Opp}"/>
                         </apex:column>                     

    </apex:pageBlockTable>
</apex:pageBlock>
</apex:form>

</apex:page>