Sample Wrapper Class using Apex in Salesforce

Sample Code:

Visualforce Page:

<apex:page controller="Sample" tabStyle="Account">
<apex:form >
<apex:pageMessages />
    <apex:pageBlock id="pg">
        <apex:pageBlockSection >
            <apex:pageBlockTable value="{!listWrapper}" var="a">
                <apex:column >
                    <apex:inputCheckbox value="{!a.checkBool}"/>
                <apex:column value="{!a.acct.Name}"/>
                <apex:column value="{!a.acct.Industry}"/>

Apex Controller:

public class Sample {
    public List<WrapperClass> listWrapper {get;set;}
    public Sample() {
        List<Account> listAcct = [SELECT Name, Industry FROM Account LIMIT 1000];
        if(listAcct.size() > 0) {
            listWrapper = new List<WrapperClass>();
            for(Account a : listAcct) {
                listWrapper.add(new WrapperClass(a));
    public class WrapperClass {
        public Boolean checkBool {get;set;}
        public Account acct {get;set;}
        public WrapperClass(Account acct) {
            this.acct = acct;



No comments:

Post a Comment

Sharing is Caring!!! Share this with your friends!!!

submit to reddit