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>