This is roughly the same question as in here, I can't comment so I'm re-asking.

My problem is that if the redirect is created in the method assigned to apex:page action attribute, the messages are still lost. I.e.

page 1:

<apex:page controller="aaTest" action="{!processtempcon}">
    <apex:commandButton action="{!processtempcon}" value="Reload"/>

page 2 (helloworld2):

<apex:page controller="aaTest">
  <apex:messages />
  <apex:outputText value="{!myint}" />

controller (aaTest):

public with sharing class aaTest{       
 public Integer myInt { get; set; }    
 public aaTest(){ myInt = 4; }

 public pagereference processtempcon(){
    pagereference p = page.helloworld2;
    apexpages.Message msg = 
      new Apexpages.Message(ApexPages.Severity.Info,'Total Number of reloads: ' + (myInt++));
    return p; 

So when I open the first page, it is correctly redirected to page 2 and the output is just "5". If I remove an action attribute in the first page and click a button, I would see a message as well as "5".

What am I missing?


looks like nobody knows the answer

  • normally, I would use apex:pageMessages here not apex:messages. You also use 'redirect' in your problem description but nowhere is there a setRedirect(true).
    – cropredy
    Jul 21, 2014 at 17:09
  • AFAIK you don't need a specific setRedirect call if you're returning pageReference. Also, if you put setRedrect(true) you'll flush all your viewstate, so you can't save anything. There is no functional difference regarding this topic between apex:pageMessages and apex:messages
    – tulumbas
    Jul 23, 2014 at 14:46
  • yes, agreed - you can display a different page within same viewstate by returning a pageref without setRedirect(true). In your case you are doing server-side redirects and I was thinking of client-side redirects. No worries.
    – cropredy
    Jul 23, 2014 at 16:48

1 Answer 1


The two pages share the controller class aaTest so fields are preserved via view state between the two pages. (This approach is commonly used for wizards.)

So whichever way processtempcon is invoked, the increment of myInt done via page 1 is preserved and presented in page 2.

(I'm answering what I think is your question of behaviour you don't expect when you remove setRedirect(true). If you can't comment or edit your question we are a bit stuck on you providing feedback if my assumption is wrong...)

  • Thanks for a comment, Keith. But I'm asking not about variables (which are a part of Viewstate), but about page messages which are not kept on redirect if redirect is called in "action" attribute as opposed to the form event.
    – tulumbas
    Jul 17, 2014 at 9:23

You must log in to answer this question.

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