0

The next button is actually not returning the results or rendering properly. Any help is much appreciated.

VF Code

   <apex:outputPanel id="Panel1">
       <apex:outputPanel id="panel2" rendered="{!NOT(ispresent))}">
         <apex:pageBlock id="pgBlockAll" >
            <apex:pageBlockTable value="{!allAccounts}" var="a" id="pgAllTable" style="width:100%">

             <apex:column >
                <apex:outputLink value="{!$Site.Prefix}/apex/acc?id={!a.id}" target="_blank">
                     {!a.Title}
                </apex:outputLink>    
              </apex:column>
              <apex:column value="{!a.id}" />
             </apex:pageBlockTable>

      <apex:commandButton value="Previous" action="{!Previous}" rerender="Panel1"
                                    status="status" disabled="{!DisablePrevious}"/>

      <apex:commandButton value="Next" action="{!Next}" reRender="Panel1"
                                    status="status" disabled="{!DisableNext}" /> 
<apex:actionStatus id="status" startText="Please Wait..."/>

 </apex:pageBlock>
 </apex:outputPanel>
 </apex:outputPanel>

Apex Class

    public with sharing class testController {
    public Integer totalRecordCount{get;set;}
    public Integer OffsetSize = 0;
    public Integer QueryLimit = 10;
    public List<Account> allAccounts{get;set;}
    public Boolean ispresent {get;set;}

    public testController(ApexPages.StandardController controller) {
      ispresent = false;
      totalRecordCount = [Select Count() from Account LIMIT 2000];
      allSearch();
    }

    public void allSearch(){
        allaccounts = Database.query('SELECT id, Title FROM account desc LIMIT :QueryLimit offset :OffsetSize');    
    }

    public Boolean getDisablePrevious(){
            if(OffsetSize>0){
                return false;
            }
            else return true;
        }

       public Boolean getDisableNext() {
            if (OffsetSize + QueryLimit < totalRecordCount){
                return false;
            }
            else return true;
        }

         public PageReference Next() {
            OffsetSize += QueryLimit;
            return null;
        }

        public PageReference Previous() {
            OffsetSize -= QueryLimit;
            return null;
        }

    }
1
  • Your SOQL Syntax is invalid. You can only use ASC|DESC as part of an ORDER BY clause.
    – Adrian Larson
    Commented Jul 6, 2016 at 17:37

1 Answer 1

3

Constructor usually used to initialize some data. E.g. you are select count from Ideas. But when you refreshing your pageblocktable, controller returns account list, which has been inialized once in constuctor.

You should create property, which return correspondent list of accounts every time:

public List<Account> getallAccounts() {
    return Database.query('SELECT id, name FROM account LIMIT :QueryLimit offset :OffsetSize');
}

Of course if user clicks, this button more than 100 times, he will got an limit exeption.

I'd reccomend to use standartsetcontroller here: check this

Also you have couple issues in your class:

  • account doesn't have field name Title
  • your query is invalid, use at least:

    SELECT id, name FROM account LIMIT :QueryLimit offset :OffsetSize

  • You are doing count from idea, but displaying account

please find my changes below:

public with sharing class testController {
public Integer totalRecordCount{get;set;}
public Integer OffsetSize = 0;
public Integer QueryLimit = 10;
//public List<Account> allAccounts{get;set;}
public Boolean ispresent {get;set;}

public testController(ApexPages.StandardController controller) {
    ispresent = false;
    totalRecordCount = [Select Count() from account LIMIT 2000];
    //allSearch();
}

//public void allSearch(){
    //allaccounts = Database.query('SELECT id, name FROM account LIMIT :QueryLimit offset :OffsetSize');    
//}

public List<Account> getallAccounts() {
    return Database.query('SELECT id, name FROM account LIMIT :QueryLimit offset :OffsetSize');
}

Vf, change to:

<apex:outputLink value="{!$Site.Prefix}/apex/acc?id={!a.id}" target="_blank">
    {!a.Name}
</apex:outputLink>

You must log in to answer this question.

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