0

I'm showing data in pagination form using offset, when i have click on last button its show an exception that is "Maximum SOQL offset allowed is 2000 " how to handlr this exception. i have set size 3 records per page and i have only 5 records but after next button click "last button " showing active but there is no more rerocd then why its not disabled working

public class Pagination {
    private integer totalRecs = 0;
    private integer OffsetSize = 0;
    private integer LimitSize = 10;
    public Pagination() {
        totalRecs = [select count() from account];
    }
    public List<account> getacclist() {
        List<account> acc = Database.Query('SELECT Name, website, AnnualRevenue, description, Type FROM account LIMIT :LimitSize OFFSET :OffsetSize');
        System.debug('Values are ' + acc);
        return acc;
    }
    public void FirstPage() {
        OffsetSize = 0;
    }
    public void previous() {
        OffsetSize = OffsetSize - LimitSize;
    } public void next() {
        OffsetSize = OffsetSize + LimitSize;
    } public void LastPage() {
        OffsetSize = totalrecs - math.mod(totalRecs, LimitSize);
    }
    public boolean getprev() {
        if (OffsetSize == 0)
            return true;
        else
            return false;
    }
    public boolean getnxt() {
        if ((OffsetSize + LimitSize) > totalRecs)
            return true;
        else
            return false;
    }
}

  <apex:pageBlock id="pb" title="Open Tasks">
                        <apex:pageblockTable value="{!acclist}" var="t">
                            <apex:column value="{!t.name}"/>
                            <apex:column value="{!t.website}"/>
                            <apex:column value="{!t.AnnualRevenue}"/>
                            <apex:column value="{!t.description}"/>
                        </apex:pageblockTable>

                       <apex:pageblockButtons location="bottom">
                            <apex:commandButton value="First" rerender="pb" action="{!FirstPage}" disabled="{!prev}"/>
                            <apex:commandButton value="Previous" rerender="pb" action="{!previous}" disabled="{!prev}"/>
                            <apex:commandButton value="Next" rerender="pb" action="{!next}" disabled="{!nxt}"/>
                            <apex:commandButton value="Last" rerender="pb" action="{!LastPage}" disabled="{!nxt}"/>
                        </apex:pageblockButtons>

7
  • You could add a try catch if that's what you mean by 'handle exception' – d_k Apr 20 '17 at 6:20
  • Catch QueryException and notify the user. – Saumya Ranjan Satapathy Apr 20 '17 at 6:25
  • Add your Vf code as well for the button not disabling issue. – Santanu Halder Apr 20 '17 at 8:05
  • @SantanuHalder i have added page code please check – cloudZigZag Apr 20 '17 at 8:45
  • @cloudZigZag did it solved by adding try-catch block? – Rohit Mourya Apr 20 '17 at 9:03
1
String errorMessage = 'Error Occured';
try {
 // SOQL Query here
}
catch (QueryException ex) {
 errorMessage += '' + ex.getMessage();
}

In your case:

String errorMessage = 'Error Occured'; // member variable
public List<account> getacclist() {
    try {
        List<account> acc = Database.Query('SELECT Name, website, AnnualRevenue, description, Type FROM account LIMIT :LimitSize OFFSET :OffsetSize');
        System.debug('Values are ' + acc);
    }
    catch (QueryException ex) {
        errorMessage = ' ' + ex.getMessage();
    }
    return acc;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.