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
RadDude89RadDude89 

why warning message won't show up on VF page

Hi,

I'm adding validation to apex class in which if a user enters a value above or below a certain figure then a warning message should appear asking the user if they wish to proceed with their selection.

However the warning message doesn't appear when the criteria is met.

The message will appear however when the criteria on the statement above (an error message) is met first. So basically for my warning message to appear, the user would have to meet the critieria of the error message first.
If they don't, then the warning message doesn't and the user can't progress to the next stage.

I tried swapping the code so the warning message was above the error message on the script but then neither message appears when the criteria is met.

See below error message and warning message.
if(offernew.Print_on_Bill__c==false && offernew.Commission_Payable_Term__c=='Monthly'){
            showpageblock4=true;
            Apexpages.addmessage(new ApexPages.Message(ApexPages.severity.FATAL,'You must check Print on Bill if Commission Payable Term is monthly')); 
            return null;
        }
         if(offernew.Commission_Value__c>0.025 || offernew.Commission_Value__c<0.001){
            Apexpages.addmessage(new ApexPages.Message(ApexPages.severity.WARNING,'Do you want to proceed with this commission value?')); 
            return null;
        }     

Does anyone now how to make this warning message appear without having to get the error message first?
Any help is much appreciated.

Thanks.

Vishal Negandhi 16Vishal Negandhi 16
Since you have two scenarios and nothing is dynamic, can't you do this?

Create two apex:pageMessage sections

<apex:outputPanel id="errorMessages" >
<apex:pageMessage rendered="{!showWarningMessage}" summary="Do you want to proceed with this commission value?" severity="warning" strength="3" />       

<apex:pageMessage rendered="{!showErrorMessage}" summary="You must check Print on Bill if Commission Payable Term is monthly" severity="error" strength="3" />
</apex:outputPanel>


so this outputpanel has both the messages. 

Now in the controller, just update the variables used in the rendered attribute. 

if(offernew.Print_on_Bill__c==false && offernew.Commission_Payable_Term__c=='Monthly'){
            showpageblock4=true;
            
            showErrorMessage = true;
           showWarningMessage = false;
        }
         if(offernew.Commission_Value__c>0.025 || offernew.Commission_Value__c<0.001){
          showWarningMessage = true;
          showErrorMessage = false;
            return null;
        }     


Now, rerender the errorMessages outputpanel and you should only see the section you want the user to see. 

Hope this helps :)
vaishali sharmavaishali sharma
Just add <apex:pagemessages> tag just below your form tag and it will work first just test it doing this.
RadDude89RadDude89

Hi Vishal,

Thanks for the reply - this will return the warning message which is perfect however when pressing the create button the page will not navigate to the next stage.  The page will just refresh with the warning message but the user will be unable to progress.