You need to sign in to do that
Don't have an account?
Accounts with associated contacts
Hi with useing <apex:repeat> trying to display accounts with associated contacts on VF page,but in controller i'm writing an relationship query as mentioned in controller.
Error:Compile Error: unexpected token: 'Select' at line 7
VF:
<apex:page controller="AsFive" sidebar="false" tabStyle="Account">
<apex:form >
<apex:message />
<apex:sectionHeader title="AssignmentFive"/>
<apex:pageBlock title="Accounts with assoicated Contacts"></apex:pageBlock>
<apex:repeat value="{!list}" var="acc">
<apex:pageBlockSection title="{!acc.name}">
<apex:pageBlockTable value="{!acc.contact}" var="con">
<apex:column value="{!con.Firstname}"/>
<apex:column value="{!con.Lastname}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:repeat>
</apex:form>
</apex:page>
Controller class
public class AsFive {
//Constructo method called
public AsFive(){
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'this page was created with only one query'));
}
public List<Account> getList() {
return [Select Name,Id (Select Firstname, Lastname FROM contacts) FROM Account order by Name];
}
}
retrun [Select Name,Id, (Select Firstname, Lastname FROM contacts) FROM Account order by Name];
<apex:pageBlockTable value="{!acc.contacts}" var="con">
Hi Vishnu7700,
You are missing a ','
SOQL should be :
Change your Visualforce Page to
and Controller to:
Also one more thing you are quering all your Accounts. You should probably limit the number of accounts that will be retrieved by SOQL.
For limiting use this SOQL :
Hello,
Try like this:
<apex:page controller="AsFive" recordSetvar="accounts" sidebar="false" tabStyle="Account">
<apex:form >
<apex:message />
<apex:sectionHeader title="AssignmentFive"/>
<apex:pageBlock title="Accounts with assoicated Contacts">
<apex:repeat value="{!accounts}" var="acc">
<apex:pageBlockSection title="{!acc.name}">
<apex:pageBlockTable value="{!acc.contact}" var="con">
<apex:column value="{!con.Firstname}"/>
<apex:column value="{!con.Lastname}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:repeat>
</apex:form>
</apex:pageBlock>
</apex:page>
Change the apex code soql query
Controller class
public class AsFive {
//Constructo method called
public AsFive(){
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'this page was created with only one query'));
}
public List<Account> getList() {
return [Select Name,Id, (Select Firstname, Lastname FROM contacts) FROM Account order by Name];
}
}
If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.
Thanks
Hey got solution!!!!
public class AssignmentFive {
//List Varaibles
Public List<account> accList{get;set;}
//Construct method
public AssignmentFive ()
{
accList = [SELECT Name, (SELECT FirstName, LastName, Phone, Email FROM Contacts) FROM Account];
}
}