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
Arun ChowdaryArun Chowdary 

i want to display 10 account records with radio buttons???


Hiii all

pls help

For my requirement I want to display  10 account records with radio buttons , 
every record before should display radio button and if I selected one radio button means one contact.The contact should open in an edit page,
if I did any modifications on that record then saved that should display after saving record in detail page.

Quick Response Appriaciable..
Thanks in advance

Thanks & Regards
Arun.N




 
Best Answer chosen by Arun Chowdary
Bhargavi TunuguntlaBhargavi Tunuguntla
Hi Arun

Please try the below code :

VF Page:
<apex:page controller="contactsRadioButtonClass">
    <apex:form>
    <apex:pageBlock id="pb">
        <apex:pageBlockTable value="{!contactList}" var="con">
            <apex:column >
                <apex:inputCheckbox value="{!BooleanVal}" >
                    <apex:actionSupport action="{!onClick}" event="onchange" reRender="pb">
                    <apex:param name="contactId" value="{!con.id}"/>
                    </apex:actionSupport>
                </apex:inputCheckbox>
            </apex:column>
        <apex:column value="{!con.name}"/>
            
        </apex:pageBlockTable>
        
        </apex:pageBlock>
    </apex:form>
</apex:page>


Class:
public class contactsRadioButtonClass {
    public Boolean BooleanVal{get;set;}
    
    public List<Contact> ContactList{get;set;}
    public contactsRadioButtonClass()
    {
        BooleanVal=false;
        contactList=new List<Contact>([select id,name from contact limit 10]);
        
    }
    public PageReference onClick()
    {
        system.debug(BooleanVal);
           Id contactId=ApexPages.currentPage().getParameters().get('contactId');
        system.debug(contactId);
        return new PageReference('/'+contactId+'/e?retURL=/'+contactId);
       
       
    }

}

Here on click checkbox this will rediret to edit page.

Thanks. 

All Answers

Raj VakatiRaj Vakati
Class 
 
public class RadioButton {
    List<contact> selectcon;
    Public List<Account> getAllContacts()
    {
        List<Account> allcons = [Select Id,Name from Account limit 10];
        return allcons;
    }    
    Public void selectcon()
    {
        String selcontactid = System.currentPagereference().getParameters().get('conid');
        selectcon = [Select Id,FirstName,LastName,Email,Phone from Contact where AccountId=:selcontactid];
       // selectcon =  new List<contact>();
        //selectcon.add(con);
    }
    Public List<contact> getselectedContact()
    {
        return selectcon;
    }
}

Page
 
<apex:page controller="RadioButton" showheader="false">
    <apex:form>
        <apex:pageblock id="allcons" title="Available Contacts">
            <apex:pageblocktable id="allcons" value="{!AllContacts}" var="allcon">
                <apex:column headervalue="Set as Primary">                    
                    <apex:actionsupport action="{!selectcon}" event="onclick" rerender="consel,allcons">  
                        <input type="radio" />                    
                        <apex:param name="conid" value="{!allcon.Id}">
                        </apex:param></apex:actionsupport>                            
                </apex:column>    
                <apex:column headervalue="Last Name">
                    <apex:outputfield value="{!allcon.Name}">
                    </apex:outputfield></apex:column> 
               
            </apex:pageblocktable>
        </apex:pageblock> 
        <apex:pageblock id="consel" title="Selected Contact">
            <apex:pageblocktable id="allcons" value="{!selectedContact}" var="selcon">                       
                <apex:column headervalue="Last Name">
                    <apex:outputfield value="{!selcon.LastName}">
                    </apex:outputfield></apex:column> 
                <apex:column headervalue="First Name">
                    <apex:outputfield value="{!selcon.FirstName}">
                    </apex:outputfield></apex:column>  
                <apex:column headervalue="Email">
                    <apex:outputfield value="{!selcon.Email}">
                    </apex:outputfield></apex:column>  
                <apex:column headervalue="Phone">
                    <apex:outputfield value="{!selcon.Phone}">
                    </apex:outputfield></apex:column>  
            </apex:pageblocktable>
        </apex:pageblock>               
    </apex:form>
</apex:page>

 
Arun ChowdaryArun Chowdary
Thanks 
Raj Vakati  for Your Response, 
Above code shows output like this:
User-added image
but as per my requirement if I select one account record, Then that record should open as a "Edit page" and if I did any modifications in that and saved that modifications should display in detail page of that account record

Thank u
Regards
Arun
Bhargavi TunuguntlaBhargavi Tunuguntla
Hi Arun

Please try the below code :

VF Page:
<apex:page controller="contactsRadioButtonClass">
    <apex:form>
    <apex:pageBlock id="pb">
        <apex:pageBlockTable value="{!contactList}" var="con">
            <apex:column >
                <apex:inputCheckbox value="{!BooleanVal}" >
                    <apex:actionSupport action="{!onClick}" event="onchange" reRender="pb">
                    <apex:param name="contactId" value="{!con.id}"/>
                    </apex:actionSupport>
                </apex:inputCheckbox>
            </apex:column>
        <apex:column value="{!con.name}"/>
            
        </apex:pageBlockTable>
        
        </apex:pageBlock>
    </apex:form>
</apex:page>


Class:
public class contactsRadioButtonClass {
    public Boolean BooleanVal{get;set;}
    
    public List<Contact> ContactList{get;set;}
    public contactsRadioButtonClass()
    {
        BooleanVal=false;
        contactList=new List<Contact>([select id,name from contact limit 10]);
        
    }
    public PageReference onClick()
    {
        system.debug(BooleanVal);
           Id contactId=ApexPages.currentPage().getParameters().get('contactId');
        system.debug(contactId);
        return new PageReference('/'+contactId+'/e?retURL=/'+contactId);
       
       
    }

}

Here on click checkbox this will rediret to edit page.

Thanks. 
This was selected as the best answer
Arun ChowdaryArun Chowdary
Hii 
Bhargavi,
How simply you resolved my issue , Its working ..

Thank you soo much..
Regards
Arun Chowdary
Ajay K DubediAjay K Dubedi
Hi Arun, 

Below code can fullfill your requirements. Hope this will work for you.

VF Page :

<apex:page controller="DiplayRelatedContacts" id="pg">
    <apex:form  id="frm">
        <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>


Controller :

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;
    }
}

Please mark this as best answer if this solves your problem.

Thank you
Ajay Dubedi