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
DhirajJain.ax414DhirajJain.ax414 

Error:In Apex Message

Hi All,
 
I am using VisualForce pages in my application with Standardcontroller as a Custom Sobject FTP_Details  .
This page has three Input fields which are manadatory,fields name like Organization,Language,Email account.
For the input field Organization, i need to display a custom message.
Hence I have added custom message in relative controller and also added tag <apex:message styleClass="error"/> in VisualForce Page.
But the custom message is not being displayed on Page.
 
Controller code:
 
public PageReference saveAndNext(){
String id;
System.debug('Organizatio is =='+details.Organization__c);
System.debug('Language is =='+details.Language__c);
System.debug('Email is =='+details.Email__c);
if(('').equals(details.Organization__c) || ('').equals(details.Email__c) || details.Language__c==null){
return null;}

try{

Integer countOrg=[Select count() from FTP_Details__c ft where ft.Organization__c=:details.Organization__c];

if(countOrg>0){

throw new ValidationException('Organization '+details.Organization__c+' exists in DataBase');

}

FTP_Details__c ftpSave=new FTP_Details__c();

ftpSave.Language__c=details.Language__c;

ftpSave.Organization__c=details.Organization__c;

ftpSave.Email__c=details.Email__c;

insert ftpSave;

id=ftpSave.Id;

}catch(ValidationException e){

ApexPages.Message myMsg = new ApexPages.Message(ApexPages.severity.ERROR,

'Error retrieving competitive wins: ' + e.getMessage());

ApexPages.addMessage(myMsg);

System.debug('Error is======'+e.getMessage());

return null;

}

String newPageUrl = '/apex/SetUpTab?userId='+id;

PageReference newPage = new PageReference(newPageUrl);

newPage.setRedirect(true);

return newPage;

}

 

VisualForce page code:

<apex:form >
      <apex:pageBlock >
       <apex:pageblockButtons >
        <apex:commandButton action="{!saveAndNext}" value="Save & Next" />
        <apex:commandButton action="{!cancel}" value="Cancel"/>
    </apex:pageblockButtons>
    <font color="red"><apex:message styleClass="error"/> </font>
                 <table>
          <tr>

Thanks in advance.
 
KeithJKeithJ
Add this to your page:
Code:
<apex:messages styleClass="error" />

 Then change your controller addMessage to
Code:
ApexPages.addMessages('');

 You have ApexPages.addMessage - one s


djaindjain

Thanks for the reply,it worked for the ValidationException mentioned in code.

But as i have mentioned all the fields in the form are mandatory,so due to <apex:messages styleClass="error"/> tag in page i get error message twice for 'Required Fields' ,one where apex messages are displayed and second below each field.

Thanks in advance.