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
Justin DJustin D 

Invalid selectOptions found. Use SelectOption type in Apex (why?)

I was trying to add a dropdown menu inside VF page (where I already have other pageBlockTables).
I only need to retrieve one field (c.sfprn) from an existing SOQL query where it is already used for other pageBlockTables.

Here is part of my VF page (where I am trying to add a dropdown menu) :

<!-- DropDown Menu starts -->
<apex:pageBlockTable value="{!RowList}" var="c">
   <apex:column >
      <apex:facet name="header">All Surveys</apex:facet>
          <span>All Surveys: </span>
             <apex:selectList id="AllSurvey" size="1">
                <apex:selectOptions value="http://www.test.com?sfprn={!c.sfprn}&id=1>Test1</apex:selectOptions>
                <apex:selectOptions value="http://www.test.com?sfprn={!c.sfprn}&id=2>Test1</apex:selectOptions>
    </apex:column>
</apex:pageBlockTable>
<!-- DropDown Menu ends -->

Here is portion of Apex code:

public PageReference searchPatients(){

        RowList = new List<TableRow2>();
        TableRow2 tr;

        for(Patient__c con : [SELECT sfprn__c, 
                                    mrn__c,
                                    LName__c, 
                                    FName__c,
                                    (select SurveySelection__c.SurveySelection__c from SurveySelections__r) 
                                    FROM Patient__c
                                    where mrn__c =:mrn 
                                    or LName__c =:lname LIMIT 1                                
                                    ]){
                                 
            tr = new TableRow2();
            tr.sfprn = con.sfprn__c;
            tr.mrn = con.mrn__c;
            tr.lname = con.LName__c;
            tr.fname = con.FName__c;
            tr.SurveySelection = con.SurveySelections__r.isEmpty() ? null : con.SurveySelections__r[0].SurveySelection__c;
            
            RowList.add(tr);
            }
         return null;   
    } 


I am curious whether I need to add a new method in Apex or I could just call the value="{!RowList}" to bring one field (c.sfprn).

Thanks in advance.  
Alain CabonAlain Cabon
Hi,

The class SelectOption can be added in the Apex code like that:
<!-- DropDown Menu starts -->
<apex:pageBlockTable value="{!RowList}" var="c">
   <apex:column >
      <apex:facet name="header">All Surveys</apex:facet>
          <span>All Surveys: </span>
             <apex:selectList id="AllSurvey" size="1">
                <apex:selectOptions value="{!items}"</apex:selectOptions>
    </apex:column>
</apex:pageBlockTable>
<!-- DropDown Menu ends -->
 
List<SelectOption> options = new List<SelectOption>();

public PageReference searchPatients(){

        RowList = new List<TableRow2>();
        TableRow2 tr;

       integer i = 1;

        for(Patient__c con : [SELECT sfprn__c, 
                                    mrn__c,
                                    LName__c, 
                                    FName__c,
                                    (select SurveySelection__c.SurveySelection__c from SurveySelections__r) 
                                    FROM Patient__c
                                    where mrn__c =:mrn 
                                    or LName__c =:lname LIMIT 1                                
                                    ]){
                                 
            tr = new TableRow2();
            tr.sfprn = con.sfprn__c;
            tr.mrn = con.mrn__c;
            tr.lname = con.LName__c;
            tr.fname = con.FName__c;
            tr.SurveySelection = con.SurveySelections__r.isEmpty() ? null : con.SurveySelections__r[0].SurveySelection__c;
            
            RowList.add(tr);

       options.add(new SelectOption('http://www.test.com?sfprn='+tr.sfprn +'&id=' + i,'TEST' + i));
       i++;

            }
         return null;   
    } 

  public List<SelectOption> getItems() { 		 	
 	 	return options;
 }

Regards
Justin DJustin D
Hi Alain. Thanks for your help. I tried your code, but it appears that URL does not work. The drop down menu works though. 
Alain CabonAlain Cabon
Hi Justin,

A button can be added near the drop down menu with a javascript function.
<script>
        function myfunc(textid) {        
           var myselect = document.getElementById(textid);
           var mychoice = myselect.selectedIndex;
           var myvalue = myselect.options[mychoice].value;
           var mytext = myselect.options[mychoice].text;
           //  alert('value ' + myvalue + ' text : ' + mytext);
           window.open(myvalue);
        }
</script>

<apex:column >
     <apex:selectList id="AllSurvey" size="1">
          <apex:selectOptions value="{!items}"></apex:selectOptions>
          <apex:commandButton value="Go" onclick="myfunc('{!$Component.AllSurvey}')"/>
     </apex:selectList>
</apex:column>

Regards