+ Start a Discussion

ApexPages.addmessage not working

Hello all,


I am using a controller to update contact details. It's saved successfully but My Error Message was not printed.


Here's code,


public pageReference SubmitUserDetails()

Contact contact = [Select  .....all query.......];

contact.phone = '123';

update contact;


ApexPages.Message apexMessage = new ApexPages.Message(ApexPages.Severity.Error, 'Your changes saved  successfully');



PageReference pageReference = new PageReference('/ContactPage?VolId='+VolSelected);

//  VolSelected is a contact Id.
return pageReference;



Here's is page tag,


<apex:Messages  />  &  <apex:pageMessages />.


I have used both one by one but its not working. Could anybody help me to get through this.


Thanks in advance.




Is "/apex/ContactPage" the page that the user is on when the error is generated?


If not, then it looks like you might be setting the message on one page and then sending the user to another.


~ Clint




"/apex/ContactPage" is another page and my current page is "editContactPage" but I have used same controller for them,


so is there no way to  print my Message.


Thanks in advance.



murali krishna.ax1501murali krishna.ax1501

i am aslo facing same issue, have you find any soluction.


Hi Murali,


When we are using below statements,

PageReference pageReference = new PageReference('/ContactPage?VolId='+VolSelected);
return pageReference;


then it will refresh your whole page, so you lost your error message also so use return page.ContactPage; or declare a success variable in controller and set it's value after success then print it in VF page.


Hope this will help.