Salesforce Visualforce – Select Record Using Radio Button
Hey!
Here we are going to learn how to show the contacts related to account and select the account using radio button with Visualforce Page.
Now, I am going to share a code that shows to record using visualforce and apex controller.
Visualforce Page:
<apex:page controller="DiplayRelatedContacts" id="pg"> <apex:form id="frm"> <h1 style="font-size:30px;"> <center> Contact Detail </center> </h1> <apex:slds /> <apex:pageBlock id="pgblk" > <apex:pageBlockTable value="{!accList}" var="ac"> <apex:column width="10px"> <input type="radio" name="group1" /> <apex:actionSupport event="onclick" action="{!dispalyContact}" ReRender="conpgblk" > <apex:param assignTo="{!accId}" name="accname" value=" {!ac.id}"/> </apex:actionSupport> </apex:column> <apex:column value="{!ac.Name}" /> <apex:column value="{!ac.AccountNumber}" /> </apex:pageBlockTable> </apex:pageBlock> <apex:pageBlock id="conpgblk" > <apex:outputPanel rendered="{!conList.size == 0}"> <b> NO RELATED CONTACTS FOR THIS ACCOUNT .</b> </apex:outputPanel> <apex:outputPanel rendered="{!conList.size != 0}"> <apex:pageBlockTable value="{!conList}" var="con"> <apex:column value="{!con.FirstName}" /> <apex:column value="{!con.LastName}" /> </apex:pageBlockTable> </apex:outputPanel> </apex:pageBlock> </apex:form> </apex:page>
Apex Code:
public class DiplayRelatedContacts { public List<Account> accList{get;set;} public list<Contact> conList{get;set;} public String accId{get;set;} public DiplayRelatedContacts(){ accList=[SELECT Id,Name,AccountNumber FROM Account LIMIT 10]; } public PageReference dispalyContact() { if(accId != null) conList=[SELECT id,FirstName,LastName FROM COntact WHERE AccountId=:accId]; return null; } }
Output
Thanks
Hail Salesforce.!
To know more visit - https://forceblogs.com