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
SFDC GuestSFDC Guest 

Display records in PageBlockTable along with Radio buttons

Hi All,

I have created custom fields Credit_Card_Name__c, Credit_Card_Number__c in Contact object. And i have created one custom object - Credit_Card__c with fields Name, Card_Holder_Email__c, Credit_Card_Number__c. 
I have created one custom button (name: Credit Card) on contact object of type (Display Type: Detail Page Button, Content Source: Visualforce Page).
I have inserted the records for Credit Card object.

When I click on custom button (name: Credit Card), I want to retrieve and display only those records which are related to Contact email in the form PageBlockTable with Radio buttons. After selecting one credit card, those details should be displayed in Contact object fields Credit_Card_Name__c, Credit_Card_Number__c.
I can achieve this by using below class. But i want to do the same using wrpapper class so that credit cards will be displayed in the form of pageBlockTable along with Radio buttons.
Thanks.

public Class ContactCreditDetailsPage
{
    private final Contact conObject = null;
    public String selectedCard{get; set;} //This is for updating selected credit card details in Contact object
    public List<Contact> con2 {get; set;} //This is for retrieving only those credit cards whose email is same as Contact record.
    public List<Credit_Card__c> ccard {get; set;}
    public List<Credit_Card__c> results; // For retrieving the credit cards from object - Credit_Card__c
    
    
    /*************
    Constructor to initialize the objects
    *********/
        public ContactCreditDetailsPage(ApexPages.StandardController stdCtr)
    {
        ccard = new List<Credit_Card__c> ();
        this.conObject = (Contact)stdCtr.getRecord();
        con2 = [select id, email, name from contact where id=:conObject.Id];
    }
    
    /**************
    For retrieving the credit cards from object - Credit_Card__c where Card_Holder_Email__c is same as Contact email
    ****************/
        public List<SelectOption> getRecords()
    {
        results = [select Name, Card_Holder_Email__c, CreditCardNumber__c, Expiry_Date__c, CVV__c from Credit_Card__c where  Card_Holder_Email__c =: con2.get(0).Email]; 
        List<SelectOption> cardList = new List<SelectOption>();
        for(Credit_Card__c cc : results)
        {
         
            cardList.add(new SelectOption(cc.Name,'Name: '+cc.name));
           
        }
        return cardList;
    }
    
    /*****************
            Method to assign Credit Card details to Contact
    ***************/
    public void retrieveCardDetails()
    {
        for(Credit_Card__c cc : results)
        {
            if(selectedCard == cc.Name)
            {
                contact conObj = new contact();
                conObj.CreditCardNumber__c = cc.CreditCardNumber__c;
                conObj.Expiry_Date__c = cc.Expiry_Date__c;
                conObj.CVV__c = cc.CVV__c;
                conObj.Credit_Card_Name__c = cc.Id;
                conObj.Id = con2.get(0).Id;
                System.debug('conObj'+conObj);
                update conObj;    
            }
        }
        
    }
    
    /********
    PageReference method to save details and redirect to Contact page
    *********/
    public PageReference save() 
    {
        PageReference nextPage = new PageReference('/' + con2.get(0).Id);
        retrieveCardDetails();
        return nextpage;
    }
    
      }

<apex:page standardController="Contact" extensions="ContactCreditDetailsPage" sidebar="false">
<apex:sectionHeader title="Credit Card" subtitle="Page"/>
    <apex:form >
   
        <apex:pageBlock title="Credit Card Details"> 
              
            <apex:selectRadio value="{!selectedCard}" >
                <apex:selectOptions value="{!Records}"/>
            </apex:selectRadio>
            
            <apex:pageBlockButtons location="top">
                     <apex:commandButton action="{!save}" title="Add selected card info in Contact" value="Add Card" />
                 
            </apex:pageBlockButtons>   
       
        </apex:pageBlock> 
    </apex:form>
</apex:page>
Current page:
User-added image

New Page should be as below:
User-added image
Lokesh KumarLokesh Kumar
Use PageBlockTable.