Saturday, June 14, 2014

View All the Account Related Contacts in single VF page.


I have one requirement that like Actvities Viewall functionality my client is asking me to display all the contact's in a single page. for example:-

Go to Account's Tab and click on account -->go to Activity History Related list and click on View all button.

Once you click on "View All" button it open a page with all the Activities.

like that we need to display a page with all the contact's of that account. to achieve for this we develop a VF page and Command link button.

Go to setup-> customize-> Contact->Buttons Links-> Create a  "New Button Link" like in the below screen shot.

save image
save image

once you create a button place the button in related list. and develop a VF page name as "Showallcontacts" 
save image

VF Page :

<apex:page controller="ShowAllContact" tabStyle="Account">
  <apex:form >
     <apex:sectionHeader title="Contact Details"/>
                 <center><apex:commandButton value="cancel" action="{!cancel}" /></center>
   <apex:repeat value="{!contlist}" var="c">
    <apex:pageBlock >
        <apex:pageBlockSection columns="1" >
            <apex:outputField value="{!c.FirstName}" />
            <apex:outputText value="{!c.LastName}" />
  <center><apex:commandButton value="cancel" action="{!cancel}" /></center>


Controller Class:

public class ShowAllContact {

 string accid= ApexPages.currentPage().getParameters().get('accid');

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

public ShowAllContact(){
  if(accid !=null )
  //contlist= [select id,firstname,lastname,phone,email from contact where accountid='0019000000wFr7E'];
  contlist= [select id,firstname,lastname,phone,email from contact where accountid=:accid];
      public PageReference cancel() {
      URL currentURL = URL.getCurrentRequestUrl();
      account acc = new account();
       // Send the user to the detail page for the new account.
        PageReference acctPage = new PageReference('/'+accid);
        return acctPage;


once you develop all the code you can view all the contacts for an Account like this.

save image

 That's it.....


Post a Comment

| ,