function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Suresh suri kSuresh suri k 

How to show more 50000+ records on visual force page?

Khan AnasKhan Anas (Salesforce Developers) 
Hi Suresh,

Greetings to you!

You can use visualforce page with a readOnly attribute set to true. You need to use the @ReadOnly annotation to enable the 1,000,000 row limit.

Normally, queries for a single Visualforce page request may not retrieve more than 50,000 rows. In read-only mode, this limit is relaxed to allow querying up to 1 million rows.

Or you can use Batch Apex to accomplish your goals. 

Please refer to the below links which might help you further with the above requirement.

https://salesforce.stackexchange.com/questions/158504/display-more-than-50000-records-in-visualforce-page

https://salesforce.stackexchange.com/questions/50305/how-to-query-more-than-50k-records-and-display-in-visualforce-page

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
Deepali KulshresthaDeepali Kulshrestha
Hi Suresh,
You can either use client-side or server-side pagination. Either way, you won't be able to use standard tools like StandardSetController or OFFSET.

Server-side, you need to use the @ReadOnly annotation to enable the 1,000,000 row limit, which might look like this:

@RemoteAction @ReadOnly public static SObject[] getRecords(Integer page) {
SObject[] results = new SObject[0];
for(SObject[] records: [SELECT ... FROM SObject WHERE ... LIMIT :page*200]) {
    results = records;
}
return results;
}
From there, you just repeatedly call the value until you get all of your results:

var buffer = []
function getPage(i) {
myController.getPage(i, function(event, data) {
     if(data.length) {
         data.forEach(function(v) {buffer.push(v)})
         getPage(i+1)
     }
}
}
Client-side, it'd look more like this example from the docs:

var result = sforce.connection.query("select id, name from account"); 
var it = new sforce.QueryResultIterator(result); 
var buffer = [];
while (it.hasNext()) { 
var account = it.next(); 
buffer.push(account);



I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha

 
Dushyant SonwarDushyant Sonwar
Hi Suresh ,

As already said by others I will  reinstate  the same , Use server side pagination and  show limited records at a time.  Showing 50000 records at a time on page will impact the performance of the page.

Regards,
Dushyant Sonwar
 
Ajay K DubediAjay K Dubedi
Hi Suresh,
For showing more than 50000 records on visual force page you can try pagination. This is the best option for your task.
Please follow these links for pagination with Vf Page:

https://blog.jeffdouglas.com/2009/07/14/visualforce-page-with-pagination/
https://mytutorialrack.com/how-to-implement-pagination-in-visualforce-with-example/
http://www.infallibletechie.com/2013/01/pagination-using-apex-in-salesforce.html

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi