I am facing some challenges into the wrapper class for getter and setter. I have displayed some records based on question types like text, checkbox, and radio option.

enter image description here

But when I clicked on a button all selected answer is mixing.

VF page

<apex:page controller="DemoPage">
    <apex:form >
        <apex:repeat value="{!ticketQList}" var="item">
            <apex:repeat value="{!item}" var="question">
                <apex:outputText styleClass="reg_label">{!question.question}</apex:outputText><br/>                                        
                <apex:inputTextarea styleClass="reg_input" rendered="{!if(question.type=='Text',true,false)}" value="{!question.textAns}" style="margin-top: 20px;"/>                                     
                <apex:selectCheckboxes rendered="{!if(question.type=='Checkbox',true,false)}"  value="{!question.checkAns}" layout="pageDirection">
                    <apex:selectOptions value="{!question.options}"/>
                <apex:selectRadio rendered="{!if(question.type=='Radio',true,false)}" value="{!question.radioAns}" layout="pageDirection">
                    <apex:selectOptions value="{!question.options}"/><br/>                                
        <apex:commandButton value="payment" action="{!payMent}"/>

apex code

public class DemoPage{    
    public List<List<TicketQuestionClass>> ticketQList {get;set;}        
    public DemoPage(){
        ticketQList = new List<List<TicketQuestionClass>>();        
        List<Ticket_Question__c> tqList = [Select Id,Question_Title__c, Question_Type__c, Ticket_Type__c,IsRequired__c, (Select Id,Option__c From Ticket_Question_Options__r) From Ticket_Question__c Where Ticket_Type__c='a012C000002Gde1'];
        System.debug('tqList --> '+tqList);        
        List<TicketQuestionClass> tempTQWC = new List<TicketQuestionClass>();
        for(Ticket_Question__c tempTQ : tqList){
            List<SelectOption> options = new List<SelectOption>();
            if(tempTQ.Question_Type__c=='Checkbox' || tempTQ.Question_Type__c=='Radio'){                
                for(Ticket_Question_Option__c objTQO : tempTQ.Ticket_Question_Options__r){
                    options.add(new SelectOption(objTQO.Option__c,objTQO.Option__c));
            TicketQuestionClass objTQWC = new TicketQuestionClass(tempTQ.IsRequired__c,tempTQ.Question_Type__c,tempTQ.Question_Title__c,options);
        System.debug('tempTQWC--> '+tempTQWC);
    public void payment(){
        System.debug('ticketQList --> '+ticketQList);       

    //-- wrapper class of ticket question
    public class TicketQuestionClass{       
        public Boolean isRequired {get;set;}
        public String type {get;set;}
        public String question {get;set;}
        public String radioAns {get;set;}
        public String textAns {get;set;}        
        public List<String> checkOption = new List<String>();
        public List<SelectOption> options {get;set;}       

        public TicketQuestionClass(Boolean isRequired,String type, String question, List<SelectOption> options){
            this.isRequired = isRequired;
            this.type = type;
            this.question = question;
            this.options = options;

        public String[] checkAns {
                String[] selected = new List<String>();             
                for(String s : checkOption) {               
                return selected;
                for(String s : value) {
                checkAns = checkOption;

Before submit records enter image description here

After submit records enter image description here

  • Please use the {} code format tool or select the region and press Ctrl-K to format your code properly. You can include headings with #. HTML comments will not display.
    – David Reed
    Jan 16 '19 at 14:17
  • Sure, I will follow the same.. Jan 17 '19 at 6:49

The problem is this line of code in your DemoPage class


if you are rendering both of those on the same VF page they are referencing the same object in the stack so updating one will update both which is why they seem to be merging. To fix this create two separate variables and add them both to the list

  • For the testing purpose, I have added 2 items into the list. at the run time, a user can fill multiple forms and select question answer but the question could be the same or different base on selected tickets and it's quantity. for Ex. If tickets quantity is more then one, so will show the same question for the different registration form. Is it possible to create different instance name of the wrapper class inside the loop? Thanks for the reply. Jan 17 '19 at 6:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.