+ Start a Discussion
N.iguN.igu 

pagenation error

No errors on the apex class screen. An unexpected error occurs when you press the search button.

I got an error when I added the pagination code in the second half.
There was no problem before that.

Why? Thank you.


 
public with sharing class AccountListCon {

    static List<String> TARGET_FIELDS = new List<String>{
      'Name'
    };

    public SearchCondition condition{ get;set; } 
    public List<AccountList__c> results { get;set; } 
    public String sortingField { get;set; }

    public void init(){
        this.condition = new SearchCondition();
        this.results = new List<AccountList__c>();
    }
    public PageReference clear(){
        init();
        return null;
    }
    public PageReference search() {

        if( condition.validate() ){
            return null;
        }

        String soqlQuery = condition.getSoqlQuery();
        System.debug('[soql] ' + soqlQuery);

        try{
            this.results = database.query(soqlQuery);
            System.debug(this.results);
        }catch(DmlException e){
            ApexPages.addMessages(e);
            System.debug('[DmlException]' + e);
        }catch(Exception e){
            ApexPages.addMessages(e);
            System.debug('[Exception]' + e);
        }
        return null;
    }

    public PageReference sort(){

        if(this.sortingField == null ){
            return null;
        }

        if(this.sortingField == this.condition.sortkey){
            this.condition.setOrderReverse();
        }
        else {
            this.condition.sortkey = this.sortingField;
        }

        search();
        return null;
    }


    public Class SearchCondition {

    private Time JST_AM0 = Time.newInstance(9, 0, 0, 0);


        public AccountList__c obj {get;set;}

        public SearchCondition() {
            this.obj = new AccountList__c();
            sortkey = 'LastModifiedDate';
            order = 'DESC';
        }

        public String getSoqlQuery(){
            List<String> param = new String[]{ getFieldList(), getWhere(), getOrder() };
            return String.format('SELECT {0} FROM AccountList__c {1} {2} LIMIT 500', param);
        }

        private String getFieldList(){
            return String.join(TARGET_FIELDS, ',');
        }

        private String getWhere(){
            List<String> param = new String[]{ };

--Omission--

            if(param.isEmpty()){
                return '';
            }
            return 'WHERE ' + String.join(param, ' AND ');
        }

        private String getOrder(){
            List<String> param = new String[]{ sortkey, order };
            return String.format('ORDER BY {0} {1}', param);
        }

        private DateTime adjustJSTtoGMS(DateTime day){
            JST_AM0 = Time.newInstance(15, 0, 0, 0);
            return Datetime.newInstance(day.date(), JST_AM0);
        }

--Omission--


        private static final Integer PAGE_SIZE = 10;
        public Integer currentPage {get; set;}
        public Integer totalPage {get; set;}
        private ApexPages.StandardSetController ssController;

        public Boolean getEnablePrev(){
            return ssController.getHasPrevious();
        }

        public Boolean getEnableNext(){
            return ssController.getHasNext();
        }

        public void PagingCtrl(){
        }


        public PageReference searchinit() {
            ssController = new ApexPages.StandardSetController([SELECT Id, Name FROM Account]);
            currentPage = ssController.getPageNumber();
            ssController.setPageSize(PAGE_SIZE);

            totalPage = (Integer)Math.ceil((Decimal)ssController.getResultSize() / PAGE_SIZE);
            return null;
        }

        public void next() {
            ssController.next();
            currentPage = ssController.getPageNumber();
        }

        public void prev() {
            ssController.previous();
            currentPage = ssController.getPageNumber();
        }

        public List<Account> getAccountList(){
            return (List<Account>)ssController.getRecords();
        }





}