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
zubair shareef mohammadzubair shareef mohammad 

doubt in ajax code

hi this is zuber
this is the visual page code and controller class return by me
and i am not getting associated contacts what mistake i did here please help to get my mistake
=======================================================================
<apex:page sidebar="false" controller="getrelatedcontacts" action="{!getaccounts}">
<apex:sectionHeader title="contacts of accounts"/>
<apex:form >
<apex:pageBlock >
<apex:actionRegion >
<apex:selectList size="1" multiselect="false" label="Account" value="{!selectedid}">
<apex:selectOptions value="{!listoptions}">
<apex:actionSupport event="onchange" action="{!getcontacts}" reRender="aj"/>
</apex:selectOptions>
</apex:selectList>
</apex:actionRegion>
<apex:pageBlockTable value="{!listcontact}" var="a" id="aj">
<apex:column headerValue="first name" value="{!a.firstname}"/>
<apex:column headerValue="second name" value="{!a.lastname}"/>
<apex:column headerValue="phone" value="{!a.phone}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
------------------------------------------------------
public class getrelatedcontacts 
{
Public list<selectoption> listoptions{get;set;}
Public list<contact> listcontact{get;set;}
Public string selectedid{get;set;}

Public void getaccounts()
{
list<account> listaccounts = [select id, name from account order by name];
if(!listaccounts.isempty())
{
listoptions = new list<selectoption>();
for(account acc: listaccounts)
{
listoptions.add(new selectoption(acc.id, acc.name));
}
}
}
Public void getcontacts()
{
listcontact = new list<contact>();
listcontact = [select id, firstname, lastname, phone from contact where accountid =: selectedid];
}
}
karthikeyan perumalkarthikeyan perumal
Hello, 

use below update ​ VisualForce page, 
<apex:page sidebar="false" controller="getrelatedcontacts" action="{!getaccounts}">
<apex:sectionHeader title="contacts of accounts"/>
<apex:form >
<apex:pageBlock >
<apex:actionRegion >
<apex:selectList size="1" multiselect="false" label="Account" value="{!selectedid}">
<apex:actionSupport event="onchange" action="{!getcontacts}" reRender="aj"/>
<apex:selectOptions value="{!listoptions}">
</apex:selectOptions>
</apex:selectList>
</apex:actionRegion>
<apex:pageBlockTable value="{!listcontact}" var="a" id="aj">
<apex:column headerValue="first name" value="{!a.firstname}"/>
<apex:column headerValue="second name" value="{!a.lastname}"/>
<apex:column headerValue="phone" value="{!a.phone}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

No change in class

Hope this will work. 

Mark Best ANSWER if its works for you..

Thanks
karthik