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
sgoremasgorema 

Datatable to show child object data

I am trying to create a VisualForce page that will display Quote and Quote Line Item (both custom objects from the AppExhange application) data. Below is my code but it is erroring out with:
Error: Invalid field SFDC_520_QuoteLine__r for SObject SFDC_520_Quote__c
 
Code:
Error: Invalid field SFDC_520_QuoteLine__r for SObject SFDC_520_Quote__c  
<apex:page renderAs="pdf"
           standardcontroller="SFDC_520_Quote__c">     
        
           <p style="text-align:center; font-size: 100%;">ONESOURCE ORDER SCHEDULE</p>
           <p style="text-align: right; font-size: 80%"> Contract No: <apex:outputtext value=" {!SFDC_520_Quote__c.Contract_Number__c}" /></p> 
           <p style="text-align: left; line-height: .05; font-size: 70%"> <b>Customer Name:</b> <apex:outputtext value=" {!SFDC_520_Quote__c.Opportunity_Account_Name__c}" /></p> 
           <p style="text-align: left; line-height: .05; font-size: 70%"> <b>Customer No:</b> <apex:outputtext value=" {!SFDC_520_Quote__c.Opportunity_Account_PMD_Id__c}" /></p> 
           <p style="text-align: left; line-height: .50; font-size: 70%"> <b>Customer Subscribes to the following OneSource On-line Service(s):</b></p> 

            <apex:dataTable value="{!SFDC_520_Quote__c.SFDC_520_QuoteLine__r}" var="Product">
            <apex:facet name="caption">table caption</apex:facet>
            <apex:facet name="header">table header</apex:facet>
            <apex:facet name="footer">table footer</apex:facet>
            <apex:column footerValue="column footer" value="{!Product.Product_Code__c}"/>
            </apex:dataTable>
            
                  
                                  
  

</apex:page>

 
 
What am I missing?
<SCRIPT type=text/javascript>// var tabId = getCookie('dmTab'); var closeButtonId = 'thePage:theForm:closeButton'; if (tabId && getBottomPanelHeight() > 28) { showCloseButton(closeButtonId, true); } else { showCloseButton(closeButtonId, false); } document.getElementById('thePage:theForm:showControllerLink').style.display = (false) ? 'inline' : 'none'; // </SCRIPT>
Best Answer chosen by Admin (Salesforce Developers) 
mtbclimbermtbclimber
Are you 100% certain that your custom object indeed has the child relationship name you are indicating here?

There have been issues in the past with relationships not having a given child relationship name. To be sure you need to either:

1: Check the enterprise WSDL
2: Use a schema browser like the one in the Force.com IDE, SoqlXplorer or similar
3: Go to the field definition in setup

Easiest is probably 3 in this case.

In the section of the field definition detail page labeled "Master-Detail Options" you should see a field label of "Child Relationship". If you see no value there then that is your problem. Click edit, give it whatever name you want then add that to your page with "__r" appended to it.

I just verified that any relationship type works (lookup or M/D).

All Answers

TehNrdTehNrd
One issue is that the value attribute for a dataTable needs to take a collection of sObjects, not a single field.
sgoremasgorema
but SFDC_520_QuoteLine__c is a child object of SFDC_520_Quote__c. But it seems that it is considering it a field rather then an object???
TehNrdTehNrd
Whoops. I didn't realize you were using a standard controller. I'm a little rusty on these but what happens when you change SFDC_520_QuoteLine__r to SFDC_520_QuoteLine__c ?
sgoremasgorema
Still thinks it is a field. I get this error now:
Error: Invalid field SFDC_520_QuoteLine__c for SObject SFDC_520_Quote__c
TehNrdTehNrd
Hmm. Sorry but I'm not sure how to pull multiple related records with the standard controller. This may require an extension. [edit] no extension required, see below


Message Edited by TehNrd on 06-19-2008 01:39 PM
dchasmandchasman
The standard controller will handle this automatically based on references in your page. Not sure exactly what is wrong in this case because I can't see the definition of the custom object and the names of the fields/relationships in the org.
sgoremasgorema

The child object  SFDC_520_QuoteLine__c has a master-detail relationship with the parent SFDC_520_Quote__c. Quote is a custom field on the SFDC_520_QuoteLine__c object and it is of type Master-Detail. What type of relationship is necessary for this to be recognized as a related list object?

mtbclimbermtbclimber
Are you 100% certain that your custom object indeed has the child relationship name you are indicating here?

There have been issues in the past with relationships not having a given child relationship name. To be sure you need to either:

1: Check the enterprise WSDL
2: Use a schema browser like the one in the Force.com IDE, SoqlXplorer or similar
3: Go to the field definition in setup

Easiest is probably 3 in this case.

In the section of the field definition detail page labeled "Master-Detail Options" you should see a field label of "Child Relationship". If you see no value there then that is your problem. Click edit, give it whatever name you want then add that to your page with "__r" appended to it.

I just verified that any relationship type works (lookup or M/D).
This was selected as the best answer
sgoremasgorema
perfect! that worked! thanks, would never have found that!