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
LindaBDLindaBD 

Page Block Table for custom objects

Hi,

I'm new to VF and am trying to understand the expressions when using custom objects and pageBlockTable.  I have object Student which has a Master-Detail relationship with object Txn (API name is Txn__c,).  The M-D field in Txn object has API name  "Student__c" and Child Relationship Name"Txn".  I want to display all transactions for a student using pageBlockTable.  THe StandardController for the page is "Student__c", right?   What is the expression for the value in pageBlockTable?  

 

In the workbook, I see to display all contacts for an account, it would be

<apex:pageBlockTable value="{! account.contacts}" var="item">

 

I've tried the values {! Student__c.Txns}, {! Student_c.Txn}, {!Student__c.Txn__c}.  I usually get the Invalid field for sObject Student message.

 

If someone can point me to a good reference, or a tip, I would appreciate it.  I know I am missing some basic foundational thing about expressions and transversing objects.

 

Thanks!

Linda

Best Answer chosen by Admin (Salesforce Developers) 
kevin lamkevin lam

Not with the apex:pageBlockTable component, have you tried the apex:relatedList component?

All Answers

kevin lamkevin lam

It should be {!Student__c.Txn__r}

LindaBDLindaBD

Thanks, Kevin.  That doesn't give me an error message, but it shows no data.  It will output a column with the data if I insert an <apex:column > statement.  I didn't want to show just one or two columns, but all the data.

 

I tried with the account and contact objects, and also get no data.  (In the URL, I am using an account id that does have a contact.)  So, I must be missing something between my start and end pageBlockTable statements.  Here is my code for that:

 

<apex:page standardController="Account">
<apex:pageBlock title="My Account Contacts">
<apex:pageBlockTable value="{! account.contacts}" var="item">
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>

 

Thanks.

kevin lamkevin lam

You need to add the apex:column component, e.g.

 

<apex:pageBlockTable value="{! account.contacts}" var="item">
<apex:column value="{!item.FirstName}"/>

</apex:pageBlockTable>

 

LindaBDLindaBD

Thanks, but is there a way to show the whole table rather than one or two columns?

kevin lamkevin lam

Not with the apex:pageBlockTable component, have you tried the apex:relatedList component?

This was selected as the best answer
LindaBDLindaBD

Thank you.  I had the wrong impression of PageBlockTable.  I'll just use RelatedList.  Thanks so much!