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
    Commented Apr 20, 2017 at 6:20
  • Catch QueryException and notify the user. Commented Apr 20, 2017 at 6:25
  • Add your Vf code as well for the button not disabling issue. Commented Apr 20, 2017 at 8:05
  • @SantanuHalder i have added page code please check Commented Apr 20, 2017 at 8:45
  • @cloudZigZag did it solved by adding try-catch block? Commented Apr 20, 2017 at 9:03

1 Answer 1

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;
}

You must log in to answer this question.

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