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
Allan NolandAllan Noland 

How can you create a subtable of a set of child records IE a pageblocktable inside of another pageblock table

Hi, 
I am pretty new to Salesforce development and for that matter development in general.  Can somebody help the rookie out?  I have a child object of the system object opportunity.  it is revenueProjection__c.  I want to create a page where the revenue projection can be easily edited by the sales folks.  I am trying to use the __r notation to traverse to the child relationship but no matter how i try it it doesn't work.  In reading all of the documentation i can find on the subject it seems like i am doing it correctly.  Of course it always does :)  Here is my code what am i doing wrong? 
 
<apex:page Standardcontroller="Opportunity" recordSetVar="Opp" standardStylesheets="True" showHeader="false"    >
    <apex:Form >
        <apex:pageBlock title="Revenue List" mode="inlineEdit">
        <apex:pageBlockButtons location="both">
            <apex:commandButton action="{!quickSave}" value="Save"/>
        </apex:pageBlockButtons>
        
            <apex:pageBlockTable value="{!Opp}" var="op" width="100%">
              <apex:Column width="100 (px)" >
                <apex:outputfield value="{!op.Name}"/>
                <apex:facet name="header">Opportunity</apex:facet>
              </apex:Column>
        </apex:pageBlockTable>
        </apex:pageBlock>
        <apex:pageBlock>
            <apex:pageBlockTable value="{!Opp.RevenueProjection__r}" var="re">
              <apex:Column width="50(px)" >
                  <apex:facet name="header">January</apex:facet>
                    <apex:outputfield value="{!re.January__c}"/>
              </apex:Column>
              <apex:Column width="50px" >
                  <apex:facet name="header">February</apex:facet>
                  <apex:inputfield value="{!re.February__c}"/>
              </apex:Column>
              <apex:Column width="50px" >
                  <apex:facet name="header">March</apex:facet>
                  <apex:inputfield value="{!re.March__c}"/>
              </apex:Column>
              <apex:Column width="50px" >
                  <apex:facet name="header">April</apex:facet>
                  <apex:inputfield value="{!re.April__c}"/>
              </apex:Column>
              <apex:Column width="50px" >
                  <apex:facet name="header">May</apex:facet>
                  <apex:inputfield value="{!re.May__c}"/>
              </apex:Column>
              <apex:Column width="50px" >
                  <apex:facet name="header">June</apex:facet>
                  <apex:inputfield value="{!re.June__c}"/>
              </apex:Column>
              <apex:Column width="50px" >
                  <apex:facet name="header">July</apex:facet>
                  <apex:inputfield value="{!re.July__c}"/>
              </apex:Column>
              <apex:Column width="50px" >
                  <apex:facet name="header">August</apex:facet>
                  <apex:inputfield value="{!re.August__c}"/>
              </apex:Column>
              <apex:Column width="50px" >
                  <apex:facet name="header">September</apex:facet>
                  <apex:inputfield value="{!re.September__c}"/>
              </apex:Column>
              <apex:Column width="50px" >
                  <apex:facet name="header">October</apex:facet>
                  <apex:inputfield value="{!re.October__c}"/>
              </apex:Column>
              <apex:Column width="50px" >
                  <apex:facet name="header">November</apex:facet>
                  <apex:inputfield value="{!re.November__c}"/>
              </apex:Column>
              <apex:Column width="50px" >
                  <apex:facet name="header">December</apex:facet>
                  <apex:inputfield value="{!re.August__c}"/>
              </apex:Column> 
          </apex:pageBlockTable>
       </apex:pageBlock>
    </apex:Form>
</apex:page>

 
Best Answer chosen by Allan Noland
Varun PareekVarun Pareek
Can you please try the below code. Also make sure you pass an opportunity Id like - /apex/YourPageName?id=<Opp_Id>
<apex:page Standardcontroller="Opportunity" recordSetVar="Opp" standardStylesheets="True" showHeader="false"    >
    <apex:Form >
        <apex:pageBlock title="Revenue List" mode="inlineEdit">
        <apex:pageBlockButtons location="both">
            <apex:commandButton action="{!quickSave}" value="Save"/>
        </apex:pageBlockButtons>
        
            <apex:pageBlockTable value="{!Opp}" var="op" width="100%">
              <apex:Column width="100 (px)" value="{!op.Name}" headerValue="Opportunity">
              </apex:Column>
            <apex:column >
			<apex:pageBlockTable value="{!Op.RevenueProjection__r}" var="re">
              <apex:Column width="50(px)" value="{!re.January__c}" headerValue="January">
              </apex:Column>
          </apex:pageBlockTable>			  
		  </apex:column >
        </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:Form>
</apex:page>

 

All Answers

Varun PareekVarun Pareek
Can you please try the below code. Also make sure you pass an opportunity Id like - /apex/YourPageName?id=<Opp_Id>
<apex:page Standardcontroller="Opportunity" recordSetVar="Opp" standardStylesheets="True" showHeader="false"    >
    <apex:Form >
        <apex:pageBlock title="Revenue List" mode="inlineEdit">
        <apex:pageBlockButtons location="both">
            <apex:commandButton action="{!quickSave}" value="Save"/>
        </apex:pageBlockButtons>
        
            <apex:pageBlockTable value="{!Opp}" var="op" width="100%">
              <apex:Column width="100 (px)" value="{!op.Name}" headerValue="Opportunity">
              </apex:Column>
            <apex:column >
			<apex:pageBlockTable value="{!Op.RevenueProjection__r}" var="re">
              <apex:Column width="50(px)" value="{!re.January__c}" headerValue="January">
              </apex:Column>
          </apex:pageBlockTable>			  
		  </apex:column >
        </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:Form>
</apex:page>

 
This was selected as the best answer
Allan NolandAllan Noland
I see how that would solve the problem for one Opportunity.  I need it to pass in all the opportunities and give the row.  It is a standard list view controller not a standard controller.

I want it to display like this

Opportunity 1
jan  feb  march april  may  june etc....

Opportunity 2
jan  feb  march april may june etc....

My hope is that it will use the recordsetVar to traverse to the RevenueProjection and create the second pageblock table then much like a for loop keep going until all the opportunities are displayed.  Obviously it will need some filtering but I want to get it working this far first.  Thanks for taking a first crack at it.  Hopefully this clarifies what I am trying to accomplish
Varun PareekVarun Pareek
Thats fine. This would work since you are using recordsetVar. It will pick up all the opportunity records. Just give it a shot.
Allan NolandAllan Noland
That worked beautifully my next problem is getting the records to save.  I think it is not letting the Revenue Projection records save because the controller is the opportunity controller.  Is that right.  What is the best way around the problem.  Do i have to write a custom controller to handle the situation?  Here is the code i am using
 
<apex:page Standardcontroller="Opportunity" recordSetVar="Opp" standardStylesheets="True" showHeader="false"    >
    <apex:Form >
        <apex:pageBlock title="Revenue List" mode="Edit">
        <apex:pageBlockButtons location="both">
            <apex:commandButton action="{!previous}" value="Previous"/>
            <apex:commandButton action="{!quickSave}" value="Save"/>
            <apex:commandButton action="{!cancel}" value="Cancel"/>
            <apex:commandButton action="{!next}" value="Next"/>
        </apex:pageBlockButtons> 
        <apex:selectList value="{!filterid}" size="1">
          <apex:selectOptions value="{!listviewoptions}"/>
      </apex:selectList>
      <apex:commandButton action="{!first}" value="Apply"/>    
            <apex:pageBlockTable value="{!Opp}" var="op" width="100%">
              <apex:Column width="100 (px)" value="{!op.Ownerid}" headerValue="Owner"></apex:Column>
              <apex:Column width="200 (px)" value="{!op.Name}" headerValue="Opportunity"></apex:Column>
              <apex:Column ><apex:inputfield value="{!op.StageName}" /></apex:Column>
            <apex:column >
            <apex:pageBlockTable value="{!Op.RevenueProjections__r}" var="re">
              <apex:Column width="50(px)"  headerValue="Year"><apex:inputfield value="{!re.Year__c}" /></apex:Column>
              <apex:Column width="50(px)"  headerValue="January"><apex:inputfield value="{!re.January__c}"/></apex:Column>
              <apex:Column width="50(px)"  headerValue="February"><apex:inputfield value="{!re.February__c}"/></apex:Column>
              <apex:Column width="50(px)"  headerValue="March"><apex:inputfield value="{!re.March__c}"/></apex:Column>
              <apex:Column width="50(px)"  headerValue="April"><apex:inputfield value="{!re.April__c}"/></apex:Column>
              <apex:Column width="50(px)"  headerValue="May"><apex:inputfield value="{!re.May__c}"/></apex:Column>
              <apex:Column width="50(px)"  headerValue="June"><apex:inputfield value="{!re.June__c}"/></apex:Column>
              <apex:Column width="50(px)"  headerValue="July"><apex:inputfield value="{!re.July__c}"/></apex:Column>
              <apex:Column width="50(px)"  headerValue="August"><apex:inputfield value="{!re.August__c}"/></apex:Column>
              <apex:Column width="50(px)"  headerValue="Setember"><apex:inputfield value="{!re.September__c}"/></apex:Column>
              <apex:Column width="50(px)"  headerValue="October"><apex:inputfield value="{!re.October__c}"/></apex:Column>
              <apex:Column width="50(px)"  headerValue="November"><apex:inputfield value="{!re.November__c}"/></apex:Column>
              <apex:Column width="50(px)"  headerValue="December"><apex:inputfield value="{!re.December__c}"/></apex:Column>
          </apex:pageBlockTable>           
          </apex:column>
        </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:Form>
</apex:page>

sorry that format is kind of weird it looks much better in the page editor.