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
KbhaskarKbhaskar 

Wrapper class for displaying Checkbox and Field Label in two colums

hi,
Below is the code for  displaying Checkbox and Field Label in two colums but i'm not able to see field name can anyone help me out !
 
<!----------- Creating this page for dispaly Opportunity fields object in single table with check box ---------->

<apex:page  controller="WrapperIntStringDisplayClass">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection >
                <apex:pageBlockTable value="{!lstwrapperIntString}" var="w">
                    <apex:column headervalue="click2Select">
                        <apex:inputcheckbox />
                    </apex:column>
                    <apex:column headervalue="Opportunity fields">
                        {!w.Id}
                        {!w.Name}                 
                    </apex:column>    
                </apex:pageBlockTable>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Apex class
public with sharing class WrapperIntStringDisplayClass 
 {
// Creating lists for the object opportunity
   List<opportunity> lsttest = new List<opportunity>();
// Creating List for Wrapper class
   public List<wrapper> lstw = new List<wrapper>();
// Get method calling from PageBlockTable and return the list of wrapper to Table
   public List<wrapper> getLstwrapperIntString() {
        lsttest = [select Id, Name from opportunity];
    for(Integer i=0;i<lstw .size();i++){
        lstw.add(new wrapper(lsttest[i].Id,lsttest[i].Name));
}
    return lstw;
}
// Wrapper Class Construction

    public class wrapper{
         public String Id{get;set;}
         public String Name{get;set;}
// Wrapper class constructor
    public wrapper(String Id,String Name ){
        this.Id=Id;
        this.Name=Name;
        }
        
    }
}

Visualforce page _
vf page
Best Answer chosen by Kbhaskar
Abhishek BansalAbhishek Bansal
Hi,

Please change your controller class with below class :
public with sharing class WrapperIntStringDisplayClass {
	public List<wrapper> lstwrapperIntString {get;set;}
	
	public WrapperIntStringDisplayClass(){
		lstwrapperIntString = new List<wrapper>();
		for(opportunity opp : [select Id, Name from opportunity]){
			lstwrapperIntString.add(new wrapper(opp.Id,opp.Name));
		}
	}
	//Wrapper Class Construction

    public class wrapper{
         public String Id{get;set;}
         public String Name{get;set;}
	// Wrapper class constructor
    public wrapper(String Id,String Name ){
        this.Id=Id;
        this.Name=Name;
        }  
    }
}

Let me know if you still have any issue.

Thanks,
Abhishek

All Answers

Abhishek BansalAbhishek Bansal
Hi,

Please change your controller class with below class :
public with sharing class WrapperIntStringDisplayClass {
	public List<wrapper> lstwrapperIntString {get;set;}
	
	public WrapperIntStringDisplayClass(){
		lstwrapperIntString = new List<wrapper>();
		for(opportunity opp : [select Id, Name from opportunity]){
			lstwrapperIntString.add(new wrapper(opp.Id,opp.Name));
		}
	}
	//Wrapper Class Construction

    public class wrapper{
         public String Id{get;set;}
         public String Name{get;set;}
	// Wrapper class constructor
    public wrapper(String Id,String Name ){
        this.Id=Id;
        this.Name=Name;
        }  
    }
}

Let me know if you still have any issue.

Thanks,
Abhishek
This was selected as the best answer
KbhaskarKbhaskar
thanks Abhishek for the help .i have another requriement just like the above one to show only opportunity Field names instead id ,name  is it possible ?
User-added image