+ Start a Discussion
Anthony ScatamacchiaAnthony Scatamacchia 

VF page help to Rollup data from a related custom object record from a related account??

I am trying to rollup data from our customer object (account_territory__c) to the account object.  Basically, I the question to answer is: "what are all the account_territory__c under a global account"?

My challenge is that the account_territory__c is related to the account object on a lower level of the account hierarchy("ean level"-individual accounts).  This allows different teams to be created for different accounts.

my visual force page works on the individual account object where the account_territory__c directly relates, but not when i test on the global account record type:

<apex:page standardController="Account">
    <apex:detail />
    <apex:pageBlock title="Territory Team">
        <apex:pageBlockSection title="Entity team">
        <apex:pageBlockTable value="{! account.Territory_Team__r}" var="item">
            <apex:column value="{!item.name}"/>
            <apex:column value="{!item.Primary_Team_Member__c}"/>

I have had success querying in the developer console for the right data with the soql query below:
SELECT Name, Primary_Coverage__c, MAX(Primary_Team_Member__c), Segment_Name__c, Region_Indicator__c, Align_Type__c, Sales_Org_Name__c, Sales_Group_Name__c, Region_Name__c
FROM Account_Territory__c
Entity__c ='001E00000073SBYIA2'
GROUP BY Name, Primary_Coverage__c, Segment_Name__c, Region_Indicator__c, Align_Type__c, Sales_Org_Name__c, Sales_Group_Name__c, Region_Name__c

I dont know how to connect the two.  Please help!!

Thank you!
Hi Anthony, 

You need to add a Controller or Controller Extension, 

See the documentation below, 

public class opportunityList2Con {
    public ApexPages.StandardSetController setCon {
        get {
            if(setCon == null) {
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator([select name,closedate from Opportunity]));
            return setCon;
    public List<Opportunity> getOpportunities() {
         return (List<Opportunity>) setCon.getRecords();

<apex:page controller="opportunityList2Con">
    <apex:pageBlock >
        <apex:pageBlockTable value="{!opportunities}" var="o">
            <apex:column value="{!o.name}"/>
            <apex:column value="{!o.closedate}"/>


Also see a similar thread,