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
giorgio70giorgio70 

Error: Invalid field for SObject when building a table of data in a Visualforce page

Hello

 

I am trying to build a table of data in a page.

 

I have used the tutorial I find in the Visualforce guide, and it works just fine.

 

-------------

<apex:page standardController="Account">
   <apex:pageBlock title="Hello {!$User.FirstName}!">
      You are viewing the {!account.name} account.
   </apex:pageBlock>
   <apex:pageBlock title="Contacts">
      <apex:pageBlockTable value="{!account.Contacts}" var="contact">
         <apex:column value="{!contact.Name}"/>
         <apex:column value="{!contact.MailingCity}"/>
         <apex:column value="{!contact.Phone}"/>
      </apex:pageBlockTable>
   </apex:pageBlock>
</apex:page>

 Now, I am trying to adjust this to match what I am trying to do.

 

I have two custom objects:

 

Program Participation (which contains a master lookup fiels to Contacts, who participated in this program)

Review (this object has a lookup field to program participation, and basically allows to enter different reviews on the program)

 

What I am trying to do is, from within the Program Participation, to display all the reviews . This is the code I have

 

<apex:page standardController="Program_Participation__c">

    <apex:pageBlock title="Hello {!$User.FirstName}!">

    You are viewing the {!Program_Participation__c.name} Program Participation record

 

          <apex:pageBlockTable value="{!Program_Participation__c.Reviews}" var="review">         <apex:column value="{!review.Name}"/>

      </apex:pageBlockTable>    </apex:pageBlock> 

   </apex:page>

 

 When I save I get this error message

 

  

Error: Invalid field Reviews for SObject Program_Participation__c

 

Does anybody have an idea why this is happening?

 

Thanks

Giorgio

Best Answer chosen by Admin (Salesforce Developers) 
Rajesh ShahRajesh Shah

The problem you are facing is that you are not referencing the child relationship properly. Salesforce generates a child relationship name that you need to reference in the page. For Account to Contact it is Contacts. But they are standard, trying the same for Child will not work. Salesforce asks for a relationship name when creating the lookup relationship or master detail relationship. If a name is not provided, a unique Id is generated. You can go and edit the relationship name later on. You can also check out the relationship name in Apex Explorer or Salesforce Schema browser in Eclipse. Go to the parent Object, drill down to the child relationships and you will find the relationship name.

 

Lets say, Custom_Object_1__c, I have a child object named, Custom_Object_2__c. The way to reference it is then {!Custom_Object_1__c.Custom_Object_2__r}

Message Edited by Rajesh Shah on 08-11-2009 12:28 PM

All Answers

Rajesh ShahRajesh Shah

The problem you are facing is that you are not referencing the child relationship properly. Salesforce generates a child relationship name that you need to reference in the page. For Account to Contact it is Contacts. But they are standard, trying the same for Child will not work. Salesforce asks for a relationship name when creating the lookup relationship or master detail relationship. If a name is not provided, a unique Id is generated. You can go and edit the relationship name later on. You can also check out the relationship name in Apex Explorer or Salesforce Schema browser in Eclipse. Go to the parent Object, drill down to the child relationships and you will find the relationship name.

 

Lets say, Custom_Object_1__c, I have a child object named, Custom_Object_2__c. The way to reference it is then {!Custom_Object_1__c.Custom_Object_2__r}

Message Edited by Rajesh Shah on 08-11-2009 12:28 PM
This was selected as the best answer
giorgio70giorgio70

Thanks Rajesh,

 

I modified my code to reflect your suggestion: Custom_Object_1__c.Custom_Object_2__r

 

and it worked

 

Thanks a lot

Giorgio