0
public with sharing class Pagination {
    Public Integer noOfRecords{get; set;}
    Public Integer size{get;set;}

    public class AccountWrapper
    {
            public Account acc {get;set;}
            public Boolean isSelected{get;set;}
            public AccountWrapper(Account a,Boolean s)
            {
                acc=a;
                isSelected=s;
            }
    }

    public ApexPages.StandardSetController setCon {
        get{
            if(setCon == null){
                size = 10;              
                setCon = new ApexPages.StandardSetController(accounts); // error on this line 
                setCon.setPageSize(size);
                noOfRecords = setCon.getResultSize();
            }
            return setCon;
        }set;
    }

    Public List<AccountWrapper> getAccounts(){
        List<AccountWrapper> accList = new List<AccountWrapper>();
        for(Account a :  [Select Name, Type, BillingCity, BillingState, BillingCountry from Account order by Name]);
            accList.add(new AccountWrapper(a,false));

        return accList;
    }

}

I am not able to pass the list of wrapper to StandardSetController. Facing issue with line.

setCon = new ApexPages.StandardSetController(accounts);

1 Answer 1

1
public with sharing class Pagination {
    Public Integer noOfRecords{get; set;}
    Public Integer size{get;set;}

        public class AccountWrapper
    {
            public Account acc {get;set;}
            public Boolean isSelected{get;set;}
            public AccountWrapper(Account a,Boolean s)
            {
                acc=a;
                isSelected=s;
            }
    }

    public ApexPages.StandardSetController setCon {
        get{
            if(setCon == null){
                size = 10;
                string queryString = 'Select Name, Type, BillingCity, BillingState, BillingCountry from Account order by Name';
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(queryString));
                setCon.setPageSize(size);
                noOfRecords = setCon.getResultSize();
            }
            return setCon;
        }set;
    }


     Public list<AccountWrapper> getAccounts(){
        list<AccountWrapper> contWpr =new list<AccountWrapper>();
        for(Account c: (List<Account>)setCon.getRecords())
              contWpr.add(new AccountWrapper(c,false));
        return contWpr;
    }


    public void next() {
        setCon.next();
            // do you operation here 
    }

    public pageReference refresh() {
        setCon = null;
        getAccounts();
        setCon.setPageNumber(1);
        return null;
    }       
}

Always you must be aware that ApexPages.StandardSetController hold only List of sObject, it will not hold the list of wrapper class object.

Find Full working Code from Bit-bucket https://bitbucket.org/nitheshk/pagenavigation

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .