0

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:pageBlock>
        <apex:pageBlockSection columns="1">
            <apex:form>
                <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>
                    <br></br>
                    <p style="font-fami1y:arial; color:red; font-size:12pt; margin-top: 0px; margin-bottom: 0px"> b. Error Message 2 </p>
            </apex:form>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:page>

enter image description here

1
  • 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, 2015 at 20:51

1 Answer 1

1

You have:

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

<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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .