function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
VacharaVachara 

Getting "ApexPages.addMessage" message to display in my VF page.

Hi,

 

I'm having trouble getting the "ApexPages.addMessage" message to display in my VF page when there's an error.  Below is the code in the extensions that validates the input before saving the record.  Any help would be greatly appreciated.  Thank you in advance.

 

"

...
    //
    //Save current record
    //
    public PageReference save(){
        if (validate_save_data()) {                    
            ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Error: Invalid Input.');
            ApexPages.addMessage(myMsg);
            return null;
        } else {
            upsert erma;
            return (new ApexPages.StandardController(erma)).view();       
        }      
    }
 
    //
    // Validate input data before saving  
    //
    public boolean validate_save_data () {
        if (erma.sales_area__c == null) {
            return true;
        } else {
            return false;
        }
    }
...
"

Best Answer chosen by Admin (Salesforce Developers) 
WesNolte__cWesNolte__c

Hey

 

Have you included:

 

<apex:pageMessages />

 

within your VF page? That's the tag that outputs page messages..

 

Wes

All Answers

WesNolte__cWesNolte__c

Hey

 

Have you included:

 

<apex:pageMessages />

 

within your VF page? That's the tag that outputs page messages..

 

Wes

This was selected as the best answer
VacharaVachara

Hi Wes,

 

That was it!  Thank you very much for your help.

 

Best,

Ta

Jay_HunterJay_Hunter

I've been struggling with this for the past hour or so.  It seems very easy, but my messages are not showing up.

 

Here's the section on the page where I want to show messages:

 

<apex:pageblock > <apex:pageblockSection > <h1>Page Messages:</h1> <apex:pageMessages /> </apex:pageblockSection>

 

And here's the controller method that's generating the messages:

 

if (billTos.size() > 0) { try{ insert billTos; // set the message for the user ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Bill-To Sites successfully created')); } catch (DMLException e){ // show the messages to the user ApexPages.addMessages(e); } } else { // set the message for the user ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'No Sites Selected')); }

 I am successfully inserting my selected records, but I never get the info message that the insert was successful.

 

On the same page, I should be able to also select no records, click the button, and get the message "No Sites Selected" but no luck there either.

 

I know there must be something stupid I'm not doing, but I can't figure it out.  Any tips appreciated!

 

 

 

Rakesh BoddepalliRakesh Boddepalli

the return type of the controller should be null .

if you have theController.view().setRedirect(true);  in your controller then you cannot view the error message.

 

R

sandeep@Salesforcesandeep@Salesforce

There are two way to display message on visualforce page from controller

1. Normal Case: 

 

to display simple message follow this 

ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.info,constantClass.'Hello'));

 

2. Exception Case:

Try {

// your code 

}catch(Exception e) 

{

   ApexPages.addMessages(e) ; 

}

 

Please mind that there two method I have explained above 

 

ApexPages.addMessage(pMessage)


ApexPages.addMessages(pAPEX_OBJECT)

 

 

Tejashri Patil 22Tejashri Patil 22
can someone explain how to add error message at the bottom of the page by using : ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Error: Invalid Input.');
Since by default it shows error at the top of the page?
Andrea BrumanAndrea Bruman
I also would like to display the message at the bottom.  Better yet at a specified field.