0

I have a one vf page which displays list of all records in Account object using controller and I am using pagination to show all records it is working fine.

But my Account records are crossed 50k records so now I am getting 50001 error.

I also tried below things but still it's not working.

  1. I tried the readonly="true" attribute in the` tag
  2. I tried database.query()

I saw some of the post we can use batch apex but my doubt is how can we link page and batchapex.

Thanks in Advance.

1
  • 3
    I think my first question would be what is the use case where you need the ability to paginate over 50,000 records. I can't think of a realistic use case for this, so I would suggest trying to limit your query with some WHERE clauses to try to cut down on the number of records. Sep 23 '14 at 19:27
1

Setting the Readonly attribute at the page level should remove the 50,000 record limit.

<apex;page standardcontroller="Account" readOnly="true">

this should open the limit to 1 million records. If you are still getting the 50001 error, you may not be setting the attribute correctly. Your other option would be to leverage the SOQL query OFFSET to create your own pagination subqueries. SOQL OFFSET

9
  • 1
    I can't comment as I don't have the reputation but the answer by JimRae is correct except that SOQL OFFSET has a limit: The maximum offset is 2,000 rows. Requesting an offset greater than 2,000 will result in a NUMBER_OUTSIDE_VALID_RANGE error.
    – Brent
    Sep 23 '14 at 20:24
  • from @jeremy_butler: "The maximum offset is 2,000 rows. Requesting an offset greater than 2,000 will result in a NUMBER_OUTSIDE_VALID_RANGE error." Sep 23 '14 at 20:38
  • That is true Jeremy. My suggestion would be to create a custom pagination model, assuming each page was 2000 records or less. Each time the user clicks a different page number the soql runs with a different offset and limit. Shouldn't need to do this at all, as ninja mentions it would be good to understand why the user would need to pull down all these records, and if it is a legit business case, the readonly tag should be sufficient.
    – JimRae
    Sep 24 '14 at 1:09
  • Thanks guys for your quick response...I tried using readonly =true but now I am getting collection size 73038 exceeds maximum size of 10000.how to store that 73038 records in list and how to display it
    – Bngrm
    Sep 24 '14 at 3:53
  • A list iterated on a a VF page is limited to 1000 items long. A list not iterated on a VF page, or iterated on a readonly page, is limited to 10,000 items. This answer shows how to make a list-of-lists so you can show all of your records. I'm with @sfdc_ninja on this though. What possible use does a list of 50k accounts have? salesforce.stackexchange.com/questions/48946/pagination-in-apex/…
    – Dominic
    Sep 24 '14 at 8:06
0

My Visual Force Page:

 <apex:outputLabel ><B>Showing {!pageNum} page out of {!totPages} pages and your viewing from {!index} record to {!pagevalue} out of Total {!totalRecs} </B></apex:outputLabel>
<c:PageBlockTableEnhancerADV targetPbTableIds="mid,mid2" paginate="true" defaultPageSize="600" pageSizeOptions="100,400,600,700,900,1000"/>
    <apex:pageblockTable value="{!tempMemb}" var="m" id="mid">

      <apex:column > <apex:inputText value="{!m.Name}"> </apex:inputText> </apex:column>
       <apex:column value="{!m.id}"/> 
        <apex:column value="{!m.Name}"/> 


    </apex:pageblockTable>
    <apex:pageblockButtons >
        <apex:commandButton value="First" rerender="details" action="{!beginning}" disabled="{!prev}" oncomplete="initPageBlockTableEnhancerADV()"/>
        <apex:commandButton value="Prev" rerender="details" action="{!previous}" disabled="{!prev}" oncomplete="initPageBlockTableEnhancerADV()"/>
        <apex:commandButton value="Next" rerender="details" action="{!next}" disabled="{!nxt}" oncomplete="initPageBlockTableEnhancerADV()"/>
        <apex:commandButton value="Last" rerender="details" action="{!end}" disabled="{!nxt}" oncomplete="initPageBlockTableEnhancerADV()"/> 
        <apex:commandButton value="Mass Update" reRender="details" action="{!massUpdate}" status="Load" oncomplete="initPageBlockTableEnhancerADV()"/>                                   
    </apex:pageblockButtons>

   <apex:actionStatus id="Load"> Loading........</apex:actionStatus>

</apex:pageBlock>

Controller:

enter preformatted text here

public class PaginationCtrl2
{    
    public integer totalRecs{get;set;}     
    public integer index {get;set;}
    public integer blockSize{get;set;}
    public integer pagevalue{get;set;}
    public integer pageNum{get;set;}
    public integer totPages{get;set;}
    public list<review__c> tempMemb{get;set;}         

    public PaginationCtrl2()
    {
        tempMemb=new List<review__c>();
        totalRecs = 0;
        index = 0;
        pageNum =1;
        blockSize = 1000;
        pagevalue = 1000;
        totalRecs = [select count() from review__c];
        totPages = (totalRecs /1000)+1;
        gettempMemb();    
    }    

    public List<review__c> gettempMemb() 
    {
        tempMemb=Database.Query('SELECT id,Name FROM review__c LIMIT :blockSize OFFSET :index');
        return tempMemb;
    }    

    public void beginning()
    {
        index = 0;
        pagevalue = index +1000;
        pageNum =0;
        gettempMemb();
    }

    public void previous()
    {
         pagevalue = index;
        index = index - blockSize;
        pageNum  = (pageNum -1)==-1?0:pageNum-1;

        gettempMemb();
    }

    public void next()
    {
        index = index + blockSize;
         pagevalue = (index +1000)>totalRecs ?totalRecs :(index +1000);
         pageNum  = (pageNum == totPages || pageNum+1>totPages) ?totPages :pageNum+1;
        gettempMemb();
    }

    public void end()
    {
        index = totalrecs - math.mod(totalRecs,blockSize);
        pagevalue = totalRecs-1000;
        pageNum = totPages;
        gettempMemb();
    }        

    public boolean getprev()
    {
        if(index == 0)
        return true;
        else
        return false;
    }  

    public boolean getnxt()
    {
        if((index + blockSize) > totalRecs)
        return true;
        else
        return false;
    }

    public void massUpdate()
    {
     update tempMemb;
    }    
}

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.