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
pallipalli 

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

Best Answer chosen by Admin (Salesforce Developers) 
Laxman RaoLaxman Rao

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

Laxman RaoLaxman Rao

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>

 

This was selected as the best answer
TrinayTrinay

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**

 

Laxman RaoLaxman Rao

+1 to Trinay,

 

If you want to show both account and contacts, you can go like that

pallipalli

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);
}
}

 

pallipalli

Hi laxman thank u ..................

pallipalli

hi Triny ,

Thanku very much .............