You need to sign in to do that
Don't have an account?
palli
Display the list of records using soql query
Hi,
how to display list of records by using below soql query ,.....
it is write code in apex class and the results in system .debug....
please help me frnds..........
using this soql query...
Select Id, Name, (Select Id, Name From Contacts) From Account
When ever you want to display some thing in visual force page you have to write get method or get property
like public list<Account> accs {get;set;}
try this:
Vf Page
public class ClassRetrieve {
public list<Account> accs {get;set;}
public ClassRetrieve()
{
accs = [Select Id, Name, (Select Id, Name From Contacts) From Account];
}
}
Class :
<apex:page controller="ClassRetrieve">
<apex:pageBlock >
<apex:pageBlockTable value="{!accs}" var="a">
<apex:column value="{!a.Name}"/>
<apex:column value="{!a.Id}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>
All Answers
When ever you want to display some thing in visual force page you have to write get method or get property
like public list<Account> accs {get;set;}
try this:
Vf Page
public class ClassRetrieve {
public list<Account> accs {get;set;}
public ClassRetrieve()
{
accs = [Select Id, Name, (Select Id, Name From Contacts) From Account];
}
}
Class :
<apex:page controller="ClassRetrieve">
<apex:pageBlock >
<apex:pageBlockTable value="{!accs}" var="a">
<apex:column value="{!a.Name}"/>
<apex:column value="{!a.Id}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>
Hi palli,
yes, you can display soql query value by following the Laxman Rao post. and you want to display the child relationship(contact) record, please make the following changes:
Class :
-----------
public class ClassRetrieve {
public list<Account> accs {get;set;}
public ClassRetrieve()
{
accs = [Select Id, Name, (Select Id, Name From Contacts) From Account];
}
}
vf page:
------------
<apex:page controller="ClassRetrieve">
<apex:pageBlock >
<apex:pageBlockTable value="{!accs}" var="a">
<apex:column value="{!a.Name}"/>
<apex:column value="{!a.Id}"/>
<apex:pageBlockTable value="{!a.Contacts}" var="ac">
<apex:column value="{!ac.Name}"/>
</apex:pageBlockTable>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>
and you want to access your childrelationship value with in your apex class you need to use two for loops and iterate the records through that loops.
**If this post is helpful to your solution, kindly mark this as the solution**
+1 to Trinay,
If you want to show both account and contacts, you can go like that
Hi,
Ok , but how to write two for loops hre , please help me ......
i want to access my childrelationship value with in my apex class \.
and i need to use two for loops and iterate the records through that loops...
my code here
=================
public class ListAccount
{
public List<Account> accts{get;set;}
public void listAcc()
{
accts=[SELECT Id,Name,(SELECT Id,Name FROM Contacts)FROM Account];
for(Account ac: accts)
{
System.debug('Display the select soql query values'+ ac);
}
}
Hi laxman thank u ..................
hi Triny ,
Thanku very much .............