1

I am attempting to display a VF page listing contacts under a Tier Level. Tier Level is a custom object that is a lookup field on the account record. For example, a contact belongs to an account. The account has an assigned Tier Level. I have the below controller. I am just putting the Contact, Account, and Tier Level records in three different lists. I then have a VF page that can print the lists individually. I need to tie together the Contact List and the Tier Level list so that it displays... Tier Level 1 Contact 1 Contact 2 Tier Level 2 Contact 3 Contact 4

I am not sure how to tie the lists together to accomplish this. Below is my code:

Controller

public with sharing class TierList_CC {

    public List<Account> accountList{get;set;}
    public List<Contact> contactList{get;set;}
    public List<Fee_and_Discount__c> feeList{get;set;}

    public TierList_CC() {

        accountList = new List<Account>();
        contactList = new List<Contact>();
        feeList = new List<Fee_and_Discount__c>();

        feeList = [select id, Name  from Fee_and_Discount__c  ];
        contactList = [select id, LastName, FirstName, account.name, account.tier_level__r.name 
                       from Contact where GC_Rep__c=true 
                       order by account.name ];
    }    
}

VF Page

<apex:page controller="FutureMeetings_CC" sidebar="false" tabStyle="Account">
    <apex:form >
    <apex:pageBlock title="Organizations and GC Contacts">
        <apex:repeat value="{!feeList }" var="fee">
            <apex:pageBlockSection title="{!fee.name}">
                <apex:pageBlockTable value="{!contactList}" var="con">
                    <apex:column value="{!con.account.name}"/>
                    <apex:column value="{!con.Firstname}"/>
                    <apex:column value="{!con.Lastname}"/>
                </apex:pageBlockTable>
            </apex:pageBlockSection>
        </apex:repeat>
    </apex:pageBlock>
    </apex:form>
</apex:page>
  • Create wrapper and pass the wrapper class to visualforce page – NITHESH K Oct 11 '17 at 4:50
  • 2
    Why not just do a single query on Account (including the tier level) with a subquery to contacts. Then you can use a map to store the accounts by tier and display as needed on your VF page. You could also use a wrapper instead of the map but seems like you would only need a single query to get the data – Eric Oct 11 '17 at 5:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.