+ Start a Discussion
vanessa veronvanessa veron 

ApexPages.Message NOT WORK

My error messages do not work.
I have a method within this method and use the code below:

global PageReference schedulejob(){
if (nomJob == null){
    ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.FATAL,'job null');

        system.schedule(NomJobSchedulable , expression, p);

PageReference pageRef = new PageReference('/apex/BBBBPage');
        return pageRef ;

Inside the Visualforce page, the button will execute this method that contains the error message, but does not work. why?

<apex:PageBlock id="block01">
  <apex:pagemessages id="showmsg" />


Nom Job.:&nbsp;<apex:inputText id="nomJobIP" value="{!nomJob}" />


 <apex:commandButton value="Create" action="{!schedulejob}"/>

Vishant ShahVishant Shah
add return null;  after ApexPages.addMessage(myMsg);
The problem here is that after adding the messages, you do a client side redirect to another page - this will discard the state of the curent page, including any messages that you have added.  You'll need to add the messages to the URL in this case, and change your target page code to pull the messages from the URL.
Vishant ShahVishant Shah
Hi Bob,

wouldnt my above suggestion stop the page redirect as we doing a redirect after setting the page message

Vishant ShahVishant Shah
sorry meant doing a return not redirect
It might - it depends on what the OP was looking to do. Just telling someone to change their code to work in a different way without explaining the underlying problem won't always help them. If the OP absolutely needs the user on the target page, then your solution would show the message but potentially break the app.  Quality of answer is always better than quantity.
Vishant ShahVishant Shah
Agreed, Thanks Bob. Will keep this in mind with my answers

vanessa veronvanessa veron
Bob I really need after clicking the button, move to a new page ...
How should I make the error message work?

Thank you
vanessa veronvanessa veron
Please, give me an example!
I haven't got an example of exactly what you are trying to do, but the following blog post:


shows how to extract parameters from the URL and use them in the controller.
vanessa veronvanessa veron
Thank you!!!!