title: Apex SOQL subquery in Visualforce
body: <p>I am looking at showing a subquery SOQL query in an Visualforce page. This is my SOQL Expression.</p>
  
  <pre><code>public ApexPages.StandardSetController setCon {
          get {
              if(setCon == null) {
                  setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
                      [SELECT Contact.Id, Opportunity.Id, Contact.FirstName, Contact.LastName, Contact.Phone,Contact.Account.Name, Contact.Email,Contact.Last_Contacted__c,Contact.Membership_Type__c,Opportunity.Call_Disposition__c, Opportunity.Sales_Stage__c,Opportunity.Name, Opportunity.CloseDate, Opportunity.StageName, Opportunity.CreatedDate FROM OpportunityContactRole where Opportunity.OwnerId=:Userinfo.getUserId()]));
              }
              return setCon;
          }
          set;
      }
  </code></pre>
  
  <p>It got a message 'OpportunityContactRole is not supported in StandardSetController'. So I tried to get Opportunity and Contact info from Account...</p>
  
  <p>So my SOQL query changed to:</p>
  
  <pre><code>SELECT Name, (SELECT Name, Phone, Email, Last_Contacted__c, Contact.Membership_Type__c FROM Account.Contacts) , (SELECT Call_Disposition__c, StageName, CreatedDate, CloseDate FROM Account.Opportunities) FROM Account where Id=:UserInfo.getUserId()])
  </code></pre>
  
  <p>but now in my Visualforce page I am not able to access the subquery fields:</p>
  
  <pre><code>&lt;apex:page controller="SalesRepPageControllerV3" tabstyle="contact" sidebar="false" showChat="true" &gt;
     &lt;apex:form id="theForm"&gt;
      &lt;apex:sectionHeader title="Sales Rep Page for {!$User.FirstName}"/&gt;
        &lt;apex:pageBlock id="innerblock" mode="edit"&gt; 
           &lt;apex:pageMessages /&gt;
  
          &lt;apex:pageBlock id="innerblock"&gt;  
          &lt;apex:pageBlockSection id="pagesection"&gt;  
              &lt;apex:pageBlockTable value="{!ContactOpportunity}" var="co" id="pageblocktable"&gt;
                &lt;apex:column headerValue="Created Date" value="{!co.Opportunity.CreatedDate}"/&gt;  
                &lt;apex:column headerValue="First Name" value="{!co.Contact.FirstName}"/&gt;  
                &lt;apex:column headerValue="First Name" value="{!co.Contact.LastName}"/&gt;
                &lt;apex:column headerValue="Phone" value="{!co.Contact.Phone}"/&gt;
                &lt;apex:column headerValue="Account Name" value="{!co.Contact.Account.Name}"/&gt;
                &lt;apex:column headerValue="Email" value="{!co.Contact.Email}"/&gt;
                &lt;apex:column headerValue="Last Contacted" value="{!co.Contact.Last_Contacted__c}"&gt;
                &lt;/apex:column&gt;
  
                  &lt;apex:column headerValue="Membership Type" value="{!co.Contact.Membership_Type__c}"/&gt;
                  &lt;apex:column headerValue="Call Disposition"&gt;
                      &lt;apex:inputField value="{!co.Opportunity.Call_Disposition__c}"/&gt;
                  &lt;/apex:column&gt;
                  &lt;apex:column headerValue="Sales Stage"&gt;
                      &lt;apex:inputField value="{!co.Opportunity.Sales_Stage__c}"/&gt;
                  &lt;/apex:column&gt;         
              &lt;/apex:pageBlockTable&gt;
             &lt;/apex:pageBlockSection&gt;
  
          &lt;/apex:pageBlock&gt;
          &lt;apex:pageBlockButtons &gt;
             &lt;apex:commandButton value="Save" action="{!save}" reRender="pageblocktable"/&gt;
             &lt;apex:commandButton value="Cancel" action="{!cancel}"  reRender="pageblocktable"/&gt;
          &lt;/apex:pageBlockButtons&gt;  
       &lt;/apex:pageBlock&gt;
       &lt;apex:panelGrid columns="2"&gt;
                &lt;apex:commandLink action="{!previous}"&gt;Previous&lt;/apex:commandlink&gt;
                &lt;apex:commandLink action="{!next}"&gt;Next&lt;/apex:commandlink&gt;
      &lt;/apex:panelGrid&gt;
      &lt;/apex:form&gt;   
  &lt;/apex:page&gt;
  </code></pre>
  
  <p>It does not understand the co.Opportunity and co.Contact as it is not a Account. And if I change it to co.Opportunities or co.Contacts it is an Arraylist which can only be accessed by repeat.</p>
  
  <p>The problem with apex:repeat is it does not have column header values which I need to sort by. Please if someone can help please let me know how.</p>