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
Gopal ChatGopal Chat 

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];  
    }
}
Best Answer chosen by Gopal Chat
Ajay K DubediAjay K Dubedi
Hi Raghav,

 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

Ajay K DubediAjay K Dubedi
Hi Raghav,

 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
 
This was selected as the best answer
Gopal ChatGopal Chat
Thanks Sir