I am getting the list from the controller :

<apex:outputPanel rendered="{!NOT(ISBLANK(quo))}">
                 <apex:outputText rendered="{!quo.size>999 }" value="Refine search Records should be less than 1000" />

i want to show this "Refine search Records should be less than 1000" without going into the next page with the below error .

I am getting the message like this :

Visualforce Error

Collection size 1 125 exceeds maximum size of 1 000.

How can i do that stay on the same page and show the message .

  • How about instead of using panel just add message in controller? – Artur Kępczyński Mar 5 '14 at 12:50

You can do this in the action method you are using to move to the next page:

public PageReference next() {
    if (quo.size() <= 1000) {
        return Page.TheNextPage;
    } else {
        Apexpages.addMessage(new ApexPages.Message(ApexPages.Severity.Info,'Refine search Records should be less than 1000'));
        return null; // Stay on same page

If you are still hitting the error then you could use limit to restrict the search results to 1000 and then display a message to let the user know that this has happened.

[select Id from Quote limit:1000];
| improve this answer | |

Governor limits cannot be handled on Apex code and Visualforce page like other exceptions.

In you scenario you can check collection size in Apex controller and show error on visualforce page

In Code

List<Account> accToAddInSelectOption = [SELECT id FROM Account];
  Apexpages.addmessage(new Apexpages.Message(ApexPages.Severity.Info,'Total Number of Records Exceed:' + accToAddInSelectOption.size());

In page add following Apex tag:

<apex:form >
| improve this answer | |

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.