You need to sign in to do that
Don't have an account?
When I select a account from radio button ,related contact will display, In my code all contacts records are displaying
<apex:page controller="SearchRecords" showHeader="true" >
<apex:form id="frm">
<apex:actionFunction name="showcon" action="{!showContact}" reRender="frm" />
<apex:pageblock >
<apex:pageBlockSection title="Search Account Records" columns="1">
Enter Name<apex:inputText value="{!getstring}" id="theTextInput"/>
</apex:pageBlockSection>
<apex:commandButton action="{!searchRecords}" value="Search" id="theSearch" reRender="frm"/>
<apex:pageBlockSection title="Account Detail">
<apex:pageBlocktable value="{!accountlist}" var="acc">
<apex:column >
<input type="radio" onclick="showcon()"/>
</apex:column>
<apex:column value="{!acc.name}" headerValue="Account Name"/>
<apex:column value="{!acc.Phone}" headerValue="Phone"/>
</apex:pageBlocktable>
</apex:pageBlockSection>
<apex:pageBlockSection title="Related Contact">
<apex:pageBlockTable value="{!Contactlist}" var="con">
<apex:column value="{!con.Name}" headerValue="Contact Name"/>
<apex:column value="{!con.Phone}" headerValue="Phone"/>
<apex:column value="{!con.Email}" headerValue="Email"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageblock>
</apex:form>
</apex:page>
public class SearchRecords {
public String AccId{get;set;}
public string getstring{get;set;}
public List<Account> accountlist {get;set;}
public list<Contact> Contactlist{get;set;}
public void searchRecords(){
accountlist= new list<Account>();
if(getstring!=null){
accountlist= Database.query('select id,name,Phone from Account where name like \'%'+getstring+'%\'');
}
}
public void showContact(){
Contactlist=[select Id,Name,Email,Phone from contact where accountId =:Accid];
}
}
<apex:form id="frm">
<apex:actionFunction name="showcon" action="{!showContact}" reRender="frm" />
<apex:pageblock >
<apex:pageBlockSection title="Search Account Records" columns="1">
Enter Name<apex:inputText value="{!getstring}" id="theTextInput"/>
</apex:pageBlockSection>
<apex:commandButton action="{!searchRecords}" value="Search" id="theSearch" reRender="frm"/>
<apex:pageBlockSection title="Account Detail">
<apex:pageBlocktable value="{!accountlist}" var="acc">
<apex:column >
<input type="radio" onclick="showcon()"/>
</apex:column>
<apex:column value="{!acc.name}" headerValue="Account Name"/>
<apex:column value="{!acc.Phone}" headerValue="Phone"/>
</apex:pageBlocktable>
</apex:pageBlockSection>
<apex:pageBlockSection title="Related Contact">
<apex:pageBlockTable value="{!Contactlist}" var="con">
<apex:column value="{!con.Name}" headerValue="Contact Name"/>
<apex:column value="{!con.Phone}" headerValue="Phone"/>
<apex:column value="{!con.Email}" headerValue="Email"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageblock>
</apex:form>
</apex:page>
public class SearchRecords {
public String AccId{get;set;}
public string getstring{get;set;}
public List<Account> accountlist {get;set;}
public list<Contact> Contactlist{get;set;}
public void searchRecords(){
accountlist= new list<Account>();
if(getstring!=null){
accountlist= Database.query('select id,name,Phone from Account where name like \'%'+getstring+'%\'');
}
}
public void showContact(){
Contactlist=[select Id,Name,Email,Phone from contact where accountId =:Accid];
}
}
Your problem has solved Please run given code.
<apex:page controller="SearchRecords" showHeader="true" >
<apex:form id="frm">
<apex:actionFunction name="showcon" action="{!showContact}" reRender="frm" />
<apex:pageblock >
<apex:pageBlockSection title="Search Account Records" columns="1">
Enter Name<apex:inputText value="{!getstring}" id="theTextInput"/>
</apex:pageBlockSection>
<apex:commandButton action="{!searchRecords}" value="Search" id="theSearch" reRender="frm"/>
<apex:pageBlockSection title="Account Detail">
<apex:pageBlocktable value="{!accountlist}" var="acc">
<apex:column >
<input type="radio" name="group1"/ >
<apex:actionSupport event="onclick" action="{!showContact}" ReRender="conpgblk">
<apex:param assignTo="{!accId}" name="accname" value="{!acc.id}"/>
</apex:actionSupport>
</apex:column>
<apex:column value="{!acc.name}" headerValue="Account Name"/>
<apex:column value="{!acc.Phone}" headerValue="Phone"/>
</apex:pageBlocktable>
</apex:pageBlockSection>
<apex:pageBlockSection title="Related Contact" id="conpgblk">
<apex:pageBlockTable value="{!Contactlist}" var="con">
<apex:column value="{!con.LastName}" headerValue="Contact Name"/>
<apex:column value="{!con.Phone}" headerValue="Phone"/>
<apex:column value="{!con.Email}" headerValue="Email"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageblock>
</apex:form>
</apex:page>
public class SearchRecords {
public String accId{get;set;}
public string getstring{get;set;}
public List<Account> accountlist {get;set;}
public list<Contact> Contactlist{get;set;}
public void searchRecords(){
accountlist= new list<Account>();
if(getstring!=null){
accountlist= Database.query('select id,Name,Phone from Account where Name like \'%'+getstring+'%\'');
}
}
public PageReference showContact(){
System.debug('AccId-->'+accId);
Contactlist=[select Id,LastName,Email,Phone from contact where AccountId =:accId];
return null;
}
}
Please mark it as best answer if you find it helpful.
Thank You
Ajay Dubedi
All Answers
Your problem has solved Please run given code.
<apex:page controller="SearchRecords" showHeader="true" >
<apex:form id="frm">
<apex:actionFunction name="showcon" action="{!showContact}" reRender="frm" />
<apex:pageblock >
<apex:pageBlockSection title="Search Account Records" columns="1">
Enter Name<apex:inputText value="{!getstring}" id="theTextInput"/>
</apex:pageBlockSection>
<apex:commandButton action="{!searchRecords}" value="Search" id="theSearch" reRender="frm"/>
<apex:pageBlockSection title="Account Detail">
<apex:pageBlocktable value="{!accountlist}" var="acc">
<apex:column >
<input type="radio" name="group1"/ >
<apex:actionSupport event="onclick" action="{!showContact}" ReRender="conpgblk">
<apex:param assignTo="{!accId}" name="accname" value="{!acc.id}"/>
</apex:actionSupport>
</apex:column>
<apex:column value="{!acc.name}" headerValue="Account Name"/>
<apex:column value="{!acc.Phone}" headerValue="Phone"/>
</apex:pageBlocktable>
</apex:pageBlockSection>
<apex:pageBlockSection title="Related Contact" id="conpgblk">
<apex:pageBlockTable value="{!Contactlist}" var="con">
<apex:column value="{!con.LastName}" headerValue="Contact Name"/>
<apex:column value="{!con.Phone}" headerValue="Phone"/>
<apex:column value="{!con.Email}" headerValue="Email"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageblock>
</apex:form>
</apex:page>
public class SearchRecords {
public String accId{get;set;}
public string getstring{get;set;}
public List<Account> accountlist {get;set;}
public list<Contact> Contactlist{get;set;}
public void searchRecords(){
accountlist= new list<Account>();
if(getstring!=null){
accountlist= Database.query('select id,Name,Phone from Account where Name like \'%'+getstring+'%\'');
}
}
public PageReference showContact(){
System.debug('AccId-->'+accId);
Contactlist=[select Id,LastName,Email,Phone from contact where AccountId =:accId];
return null;
}
}
Please mark it as best answer if you find it helpful.
Thank You
Ajay Dubedi