I have a VF page and extensions for it where I perform update operation. If it is successful or not I want to display page message - on VF I have

 <apex:pageMessages />

and in Apex controller I have

 ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Update successful'));

However, when I click button which invoke my update operation I need to perform as well page refreshing. So I have


on my button. This causes that I cannot see my page messages since the page is refreshed immediately. Any help would be appreciated.

EDIT: some more code

    public PageReference update() {
       // my logic
         try {
             update myMap.values();
             ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Update successful'));
             return null;
         } catch(DmlException ex) {
             ApexPages.Message errorMessage = new     ApexPages.Message(ApexPages.Severity.ERROR, ex.getDmlMessage(0));
             return null;

    <apex:page standardController="MyObject__c" extensions="MyController" standardStylesheets="true" sidebar="false" docType="html-5.0">

     <html xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
     <apex:stylesheet value="{!URLFOR($Resource.SLDS214, '/assets/styles/salesforce-lightning-design-system.min.css')}" />

     <div class="slds">
         <apex:pageMessages />
         <button onclick="callUpdate(); return false;" class="slds-button slds-button--brand"> Save </button>
        <apex:actionFunction name="UpdateAction" action="{!update}" reRender="panel" oncomplete="setTimeout(location.reload(),5000)" />


        function callUpdate() {
  • Why don't you use PageReference navigation instead? Then you can have your action return null in the error case and have it not redirect.
    – Adrian Larson
    Jan 4, 2017 at 20:55
  • Returning null from the action that the button invokes will re-display the page including the message you added.
    – Keith C
    Jan 4, 2017 at 20:55
  • Ok, my action return null PageReference but it does not refresh the content of my page.
    – rmatusiak
    Jan 4, 2017 at 20:59
  • Does the button specify a reRender Id so that only part of the page updates? Remove that.
    – Keith C
    Jan 4, 2017 at 21:20
  • No it doesn't. I added more code in first post.
    – rmatusiak
    Jan 4, 2017 at 21:45

1 Answer 1


instead of reloading immediately, you could set a timeout:

oncomplete="setTimeout(function() { location.reload() },1000)"

Feel free to adjust the 1000 value to whatever you like (1000 is 1 second).

You could also have this be an actionFunction that simply reRenders, which would clear the message:

<apex:actionFunction name="refresh" reRender="form" />

... oncomplete="setTimeout(refresh, 1000)" />

As for why your messages are not appearing:

It seems that you're reRendering a part of the page that does not include the apex:pageMessages. They're not rendered because the element wasn't targeted for rerendering.

<apex:pageMessages id="messages" />


    <apex:actionFunction name="UpdateAction" action="{!update}" reRender="panel,messages"
     oncomplete="setTimeout(function() { location.reload() }, 5000)" />
  • In this case my page messages are not displayed
    – rmatusiak
    Jan 4, 2017 at 21:28
  • @rmatusiak Then you're doing something else wrong. We don't have enough code to know what's wrong...
    – sfdcfox
    Jan 4, 2017 at 21:31
  • I put some more code. I have to use button instead of apex:commandButton due to SLDS styling on salesforce classic
    – rmatusiak
    Jan 4, 2017 at 21:38
  • @rmatusiak Editing...
    – sfdcfox
    Jan 4, 2017 at 21:50
  • You are right, it resolves the issue. Maybe one more, small thing. I set timeout to 5000, then to 10000 but it happens immediately actually...
    – rmatusiak
    Jan 4, 2017 at 21:58

You must log in to answer this question.

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