I know we cannot display more than 50000 records(or probably even much higher) in a Visualforce Page without avoiding viewstate. From an external webservice I am getting more than 50000 records and my senior manager tells me to display these records on the page.

My answer to this is its not possible but he wont listen.

  • 1
    you can try using remoting, and query them chunk by chunk
    – kurunve
    Commented Feb 1, 2017 at 13:04
  • 1
    at single page you cannot show 50000 records it will definitively hit VIEW STATE error. so show in format of pagination. Commented Feb 1, 2017 at 13:07
  • @kurunve, can u pls elaborate? I am aware of remote action, but didnt understand clearly the phrase chunk by chunk. In addition what else can be done without hitting viewstate? Commented Feb 1, 2017 at 13:08
  • 1
    You only have view state if your page contains an <apex:form> tag.
    – Adrian Larson
    Commented Feb 1, 2017 at 15:23

2 Answers 2


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

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(); 
  • in server side the list variable "results" cannot hold more than 50K records. then how the loop is running? Commented Feb 1, 2017 at 13:28

I believe you just want them to be shown on VF page.

So you can use javascript remoting. JS remoting will call your websrrvice. You will get the JSON response.

On your VF page, parse the JSON response and display these in form of tables using Javascript.


JS remoting doesnt consume ViewState. And once you get data in json onto browser you can create own tables and display in format you want.

Also if it is for Viewing purpose, its advised to not insert those records onto your database.

Note: You cannot insert more than 10000 records in a transaction.

  • cud u pls tell me how to call webservice thru javascript remoting,shud we use apex class to call webservice or call it in vf page?pls elaborate Commented Feb 2, 2017 at 5:00

You must log in to answer this question.

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