+ Start a Discussion

Visual Force compile problem Error: Invalid field Contract_item__c for SObject Account

I need help to resolve this page .  I want to display the line items of a contract, which reside on a custom object names Contract Item, on the account record page.  The Contract Item is a child of the Standard contracts object and has a lookup relationship to the account.  I took the code sample from the VF dev guide for the account contact example and modified it to my needs but cannot get it to complile I get the follwing error: Error: Invalid field Contract_item__c for SObject Account 


I have tried using the contract_item, contract_item__c  for the value parameter on the pageblock table and get this error every way I have tried.


The idea is to have the items show on the account pagelayout as a VF for user convenience.  I do not need to show the contract parent here, it is fine as a related liet, but the items I need to show withint the acct header layout.  Any help is greatly appreciated as my VF skills are limited.


Here is the code:

<apex:page standardController="Account">
   <apex:pageBlock title="Contract Item Viewer!">
      Contract Items for the {!account.name} account.
   <apex:pageBlock title="Contract Item Viewer">
      <apex:pageBlockTable value="{!account.Contract_item__c}" var="items">
         <apex:column value="{!items.Negotiation_Type__c}"/>
         <apex:column value="{!items.Discount_Type__c}"/>
         <apex:column value="{!items.Discount_Percent__c}"/>
         <apex:column value="{!items.Amount__c}"/>
         <apex:column value="{!items.Page__c}"/>
         <apex:column value="{!items.Day_of_Week__c}"/>
         <apex:column value="{!items.Right_Location__c}"/>
         <apex:column value="{!items.Section_Description__c}"/>
         <apex:column value="{!items.Position_Description__c}"/>
         <apex:column value="{!items.Contract__c}"/>
         <apex:column value="{!items.Ad_Unit__c}"/>
         <apex:column value="{!items.Special_Terms__c}"/>







You need to use the Relationship Name of the field.  If you use the schema browser in the force.com IDE you can see this pretty easily under the field on the Account.  It is probably Contract_Items__r (note the plural).


You can also see it in Salesforce on the Child Object (Contract_Item__c object definition) on the Account field.  There should be a Child Relationship name attribute (probably Contract_Items).  Note that you'll still have to append the '__r' after whatever you see in the Child Relationship name attribute.