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
EMasterEMaster 

Simple VF page showing filtered list of Contacts

I am new to force.com development and would like to create a VisualForce page to do the following: 

 

  • Create a list of Contact 'Names' related to an Account, filtered by a partcular checkbox field in the Contact.

 

I want to add that page to a Section in the Account Page layout.

 

Can anyone give me some hints/examples on how i would loop through the related Contacts, apply this filter, and return a list i can display on the VF page.

 

Thanks.

 

IspitaIspita

Hi EMaster,

The functionality you wish to implement using VF page in a section can be impolemented using a repeter to iterate over a collection of contacts.

 

VF Code:
<apex:page controller="MyController" tabStyle="Contact">
<apex:form>
  <apex:pageBlock title="Contacts">
  <apex:dataTable value="{!myContacts}" var="aContact" width="100%">
  <apex:column>
  <apex:facet name="header"><b>Name</b></apex:facet>
  <apex:commandLink action="{!invokeService}" value="{!aContact.name}"      rerender="resultPanel">
  <apex:param name="id" value="{!aContact.id}"/>
  </apex:commandLink>
</apex:column>
<apex:column>
  <apex:facet name="header"><b>Account Name</b></apex:facet>
 {!aContact.Account.Name}
</apex:column>
</apex:dataTable>
</apex:pageBlock>
<apex:pageBlock title="Fetched Data">
 <apex:outputPanel id="resultPanel" layout="block"> 
  Result: {!fetchedData}
 </apex:outputPanel>
</apex:pageBlock>
</apex:form>
</apex:page>


 

Controller Code:-

public class MyController {
public List<Contact> getMyContacts() {
  return [SELECT Id, Name, Account.Name FROM Contact ORDER BY LastModifiedDate DESC LIMIT 10];
}
}

 Hope this helps...

EMasterEMaster

Thank you very much Ispita 

 

I can seem to get it working to produce this (shows all Contacts for all Accounts).......

 

However, how do i then get it to appear in a Section in the Account Page Layout and only show the Contacts for that specific Account?