I have VF page shown in the service console. When Apex command button is clicked it is invoking controller action method. OnComplete on the command button executes the JS function which refreshes the Tab in the service console. Controller action method does validation and if validation fails it creates entry to be shown in ApexPageMessage and returns null.

Ideal Behavior

When Command button is clicked - action method is called, if validation fails, Apex Page Message should display the error on the page and OnComplete JS should not be invoked.


When command button is clicked - action method is called and if validation fails, the pagemessage is not shown on the Page. Instead JS function is called.

How do I make sure PageMessage are displayed when OnComplete Js is used.


Everything works as expected if I remove the "OnComplete" JS from Commandbutton.


<apex:commandButton value="ClickMe" action="{!Save}" oncomplete="refreshConsoleTab('{!IsValid}');"/>


public PageReference Save()
        ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Validation failed'));   
        return null;
        //DML statements ;
        return null;

1 Answer 1


When you specify the oncomplete attribute, VF is going to perform a Javascript AJAX postback rather than a full page post back to Salesforce. In the full page postback scenario, the entire page is rendered again, including your error messages. In the ajax postback, you've got to be explicit about which parts of the page you want rerendered when that action completes.

If you add a rerender="messages" or whatever the id is of your <apex:pageMessages /> tag to the commandButton, when the AJAX post is finished Salesforce will rerender the messages element on the page and show the (now updated) validation error message.

You must log in to answer this question.

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