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

datatable to retrieve subset of contacts for an account?

We have an issue where we have some accounts that have literally 1000's of contacts associated to them. The Sales Rep is really only concerned with a small subset of these contacts and so we would love to have either a seperate related list or even a new view that would should show their 'Sales Contacts'. Is this something that VisualForce could do? Is it possible to add a filter to the datatable component?
You can do this in an apex custom controller or an extension of the account standard controller.

Here's a quick and dirty example for you.....

<apex:page standardController="Account" extensions="accountContactExt">
<apex:relatedList list="Contacts"/>
<apex:pageBlock title="Sales Contacts">
<apex:pageBlockList value="{!salescontacts}" var="c">
<apex:column headerValue="Action">
<apex:outputLink value="{!URLFOR($Action.Contact.Edit,}" style="font-weight:bold">Edit</apex:outputLink>
<apex:column headerValue="Contact Name"><apex:outputLink value="{!URLFOR($Action.Contact.View,}">{!}</apex:outputLink></apex:column>
<apex:column value="{!c.title}"/>
<apex:column headervalue="Email"><apex:outputField value="{!}"/></apex:column>
<apex:column value="{!}"/>


public class accountContactExt {

Account a;

public accountContactExt(ApexPages.StandardController controller) {
a = (Account) controller.getRecord();

public List<Contact> getSalesContacts() {
return [select name, title, email, phone from contact where accountid =];

Just add your filter to the SOQL query.


Could someone help me writing the test class for this? thanks