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
sgoremasgorema 

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?
mtbclimbermtbclimber
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.....

PAGE:
<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,c.id)}" style="font-weight:bold">Edit</apex:outputLink>
</apex:column>
<apex:column headerValue="Contact Name"><apex:outputLink value="{!URLFOR($Action.Contact.View,c.id)}">{!c.name}</apex:outputLink></apex:column>
<apex:column value="{!c.title}"/>
<apex:column headervalue="Email"><apex:outputField value="{!c.email}"/></apex:column>
<apex:column value="{!c.phone}"/>
</apex:pageBlockList>
</apex:pageBlock>
</apex:page>

CONTROLLER EXTENSION:

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 = :a.id];
}
}

 
Just add your filter to the SOQL query.

jaw99KCGjaw99KCG

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