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
JGrafJGraf 

My First Visualforce Page

I am trying to display all the Child Records within a "pageBlockTable" using the parent as the Standard Controller but I can't seem to figure out the correct Value.  How do I identify the correct term?  

 

While I'm here, I don't seem to understand the idea behind the "var".  Is this something I need?

@anilbathula@@anilbathula@

Hi JGraf,

 

Just try this code:-

Public Class urcontrollername{
public parent_object l {get;set;}
public list<ur_child_object> Com{get; set;}
id str;

public ur_controllername(ApexPages.StandardController controller) {
l=(ur_parent_obj)controller.getRecord();
str=Apexpages.currentpage().getparameters().get('id');
com=[select id,name from ur_child_object where parent_object_lookup_field=:str limit 1000];
}
}
---------------------
vf page
---------------------
<apex:page standardController="ur_parent_object" extensions="urcontrollername" >
<apex:form>
<apex:pageBlock >
<apex:pageBlockTable value="{!com}" var="c" title="Child" >
<apex:column value="{!c.Name}"/>
<apex:column value="{!c.ur_field}"/>
<apex:column value="{!c.ur_field2}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

 

Thanks

Anil.B

Daniel.ReidDaniel.Reid

Hello JGraf,

 

The code posted above should point you in the right direction. As far as your question about "var" goes, maybe I can help illuminate that a bit more.  The pageblocktable is an automatic way of setting up a data table on a VF page.  It does most of the work for you, as compared to standard html. That being said, you still need to specify what you want it to show.  Let's take an example of the Account object (just like in the documentation example).

The Account object actually contains several fields and associated objects, in order to specifiy what exactly you want to display you need to identify it explicitly.

 

The bit at line 7 of the example code ( value="account.Contact" ) is saying that you want the table to access the Contact sub-object of Account.  

 

The next part (var="contact") is saying that you want to look at each contact as a separate object AND also that you want to refer to it as 'contact' (you could call it anything at all, but its best to use something meaningful and clear).  

 

Now that you have established what object the table will be working with, you can then specify the fields from that object that you want to show by using the name you gave it (with var) and the name of the field (i.e. contact.name, contact.MailingCity).

 

tl;dr; 

with a pageblocktable, you need the Value field to tell it "where" the information is, and you need the Var field to move across it.

 

Let me know if I can help clear it up more for you.

 

Daniel Reid
Contact us - We can help!

Salesforce Superheroes
------------------------------
help@salesforcesuperheroes.com
www.salesforcesuperheroes.com
1-888-407-9578 x102

JGrafJGraf

This code was very helpful.  It worked when I only called out the name column.  But I received a Visualforce Error when I attempted to return more columns.  This is the error message I received:

 

System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: AcctSeed__Project_Task__c.Model_Number_1__c 

 

Did I miss a step somewhere?

@anilbathula@@anilbathula@

Hi ,

 

Just add the field in the query.

Model_Number_1__c  and in the query.

 

Thanks

Anil.B