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
Michele Kleinhomer 10Michele Kleinhomer 10 

VS page to display an account's primary & related contacts

I have a VF action butotn on the account record that currently shows the contacts that have that account listed as their primary account.  I would also like to include in the list contacts that have been "related" to that account as well.  Below is my current apex and VF code.

public with sharing class DisplayContactsmk
    ApexPages.StandardController con;
    account ee;
    List<Account>lstaccount = new List<Account>();
    List<contact>lstcontacts = new List<contact>();
    public DisplayContactsmk(ApexPages.StandardController controller)
        // employee__c ee=(employee__c)controller.getRecord();
    public List<contact>getconts()
            lstaccount=[select id,name from Account where name=:ee.Name];
        for(Integer i=0;i<lstaccount.size();i++)
        lstcontacts=[select id,name,lastname, firstname, title, email, rcc_rep__c, tac_rep__c, wac_rep__c, 
                     gc_rep__c,phone,accountId from contact where accountid in:accIds order by lastname];
        return lstcontacts;
    set<string>accIds = new set<string>();

VF Page
<apex:page standardController="account" extensions="DisplayContactsmk">
    <apex:form id="f1">
    <apex:pageBlock >
        <apex:pageBlockSection >
            <apex:outputField rendered="FALSE" value="{!}"/><br/>
          <apex:pageBlockTable align="center" columnswidth="100px, 100px, 100px, 100px" border="1" value="{!conts}" var="c" id="tbl">
              <apex:column headerValue="Last Name">
                  <apex:outputLink value="/{!c.ID}">{!c.lastname}</apex:outputLink>
                    <apex:column headerValue="First Name" value="{!c.firstname}"/>
                    <apex:column headerValue="Phone" value="{!}"/>
                     <apex:column headerValue="Email" value="{!}"/>

Paul S.Paul S.
Michele - when I run this in a dev org, I get a list of contacts.  Is it not behaving the way you expected?
Michele Kleinhomer 10Michele Kleinhomer 10
I figured out my problem. This code was only giving a list of directly related contacts. I wanted direct and indirect. I changed my SOQL to select from the AccountContactRelationship table and now it works well. Michele