I would like to retrieve the contacts related to each account using the apex class. I tried but I am getting the list of accounts on page. Can someone tell me how to achieve this?
Apex Class
public class operations_class
{
public List<Contact> result{get;set;}
public List<Account> accList = [Select Id from Account];
public operations_class()
{
result=new List<Contact>();
}
public void search()
{
result=[Select FirstName, LastName, Email from Contact Where account.Id=:accList];
}
}
VF Page
<apex:page controller="operations_class">
<script>
window.onloadstart = function()
{
hello()
{
}
}
</script>
<apex:form>
<apex:actionFunction name="hello" action="{!search}">
<apex:pageBlock>
<apex:pageBlockTable value="{!result}" var="con">
<apex:column value="{!con.FirstName}"/>
<apex:column value="{!con.LastName}"/>
<apex:column value="{!con.Email}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:actionFunction>
</apex:form>
</apex:page>