How to display an error message on a visualforce page when a picklist value on a salesforce page is selected?

For example, if the Country is the picklist field, and the chosen value is Canada, an error message should trigger.

The challenge I'm having is getting the error to fire based on the picklist value being selected.

I get this error on my salesforce page:

"Content cannot be displayed: Invalid selectOptions found. Use SelectOption type in Apex."

Any help or insight would be much appreciated.

The below code is one way I've tried to do this:

@MarkPond: thankfully someone invented OCR:

<apex:page standardController="Case" showHeader="faise" standardSty1eSheets="fa1se">
        <apex:pageBlockSection columns="1">
                <apex:selectList value="{!Case.Application_Type c}" multiselect="false">
                    <apex:selectOptions value="{!"Personal Account"}"/>
                    </apex: selectList>
                    <p style="font-family:arial; color:red; font-size:12pt; margin-top: 0px; margin-bottom: 0px"> <b>Reminder:</b> a. Error Message 1 </p>
                    <p style="font-fami1y:arial; color:red; font-size:12pt; margin-top: 0px; margin-bottom: 0px"> b. Error Message 2 </p>

enter image description here

  • 2
    Hey @MarkNeufeld, not sure if I speak for everyone here but I find it more helpful if you type out your code so I can select pieces of it and whatnot. – Adrian Larson Aug 12 '15 at 20:51

You have:

<apex:selectList value="{!Case.application_type__c}" multiselect="false">
  <apex:selectOptions value="{!"Personal Account"}"/>

<apex:selectOptions> attribute value= needs to be bound to a controller variable of type List<SelectOption> with a public getter that in turn is the list of available SelectOption that you wish to show.

The syntax {!"Personal Account"}" is not a valid valid controller reference and hence error message.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.