i want to perform an action on onComplete event of commandbutton.I am calling javascript function ,in that function i want to know if there is any error displaying on visualforce page(Validation error).Can i implement this without using any controller.


I wonder if you can use the css class errorMsg of the error block:

enter image description here

If this class exists on the page - there is an error:

function checkIt(){
    if (jQuery('.errorMsg').length > 0){
        // Error exists
        alert('There is an error on the page!');
        alert('No errors!');

<apex:commandButton reRender="none" oncomplete="checkIt();" value="Click me"/>


Well, you can definitely call ApexPages.hasMessages() from your apex. There's even a version that lets you specify the severity (WARNING, ERROR, FATAL, INFO) that you're looking for.


To use this in your javascript, you could make a controller property or method that returns this result, and then simply access it via mergefield. So for example, you might define a controller method:

public Boolean ErrorsPresent(){
    return ApexPages.hasMessages(ApexPages.Severity.ERROR);

Then your Javascript might looks like

    alert('Woah there, buddy! Looks like there may be a problem');
  • While that is an interesting solution, the OP specifically asked for something that did not require a controller. – Mike Chale Oct 2 '13 at 19:57
  • Ahh, that's actually the exact problem I had been trying to solve when I stumbled across this post, but without the use of Javascript – RenegadeCoder Oct 3 '13 at 20:50

Pages with a StandardController expose a property:


Without the need for a custom controller or extensions, can do things like:

<apex:pageBlock rendered="{!ISNULL(Messages)}">
    <!-- detailed troubleshooting instructions -->

<apex:pageBlock rendered="{!NOT(ISNULL(Messages))}">
    <!-- normal page functionality -->

I found that adding '.empty' to the end was just getting stripped on save, but ISNULL worked fine, as in the following example:


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.