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
THARUN REDDY BOMMAREDDYTHARUN REDDY BOMMAREDDY 

Invalid selectOptions found. Use SelectOption type in Apex.

Could anyone please let me know why I'm getting the error Invalid selectOptions found. Use SelectOption type in Apex during preview of the below visualforce page

public  class DynamicApex {
    public Map<String ,Schema.SObjectType> gd {set;get;}
    public List<String> objlist {set;get;}
    public List<SelectOption> sop {set;get;}
    public  DynamicApex() 
    {
        objlist=new List<String>();
        sop=new List<SelectOption>();
        gd= Schema.getGlobalDescribe();
        objlist.addAll(gd.keyset());
        objlist.sort();
        System.debug(objlist);
        for(String s: objlist)
        {
            SelectOption sa= new SelectOption(s,s);
            sop.add(sa);

        }    }}

<apex:page controller="DynamicApex">
<apex:form>
  <apex:pageBlock>
    <apex:pageBlockSection>
      <apex:pageBlockSectionItem>
         <apex:outputLabel value="Select Object"/>
         <apex:selectList size="1">
            <apex:selectOptions value="{!objlist}"/>
         </apex:selectList>
      </apex:pageBlockSectionItem>
    </apex:pageBlockSection>
  </apex:pageBlock>
</apex:form>      
</apex:page>
Pasan   EeriyagamaPasan Eeriyagama
Below example from Documentation (https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_selectOptions.htm) could be useful. You could use Apex dataList or iteration.
 
<!-- Page: -->
<apex:page controller="sampleCon">
    <apex:form>
        <apex:selectCheckboxes value="{!countries}" title="Choose a country">
            <apex:selectOptions value="{!items}"/>
        </apex:selectCheckboxes><br/>
        <apex:commandButton value="Test" action="{!test}" rerender="out" status="status"/>
    </apex:form>
    <apex:outputPanel id="out">
        <apex:actionstatus id="status" startText="testing...">
            <apex:facet name="stop">
                <apex:outputPanel>
                    <p>You have selected:</p>
                    <apex:dataList value="{!countries}" var="c">a:{!c}</apex:dataList>
                </apex:outputPanel>
            </apex:facet>
        </apex:actionstatus>
    </apex:outputPanel>
</apex:page>
  			
/*** Controller: ***/
public class sampleCon {
    String[] countries = new String[]{};
 
    public PageReference test() {
        return null;
    }
 
    public List<SelectOption> getItems() {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('US','US'));
        options.add(new SelectOption('CANADA','Canada'));
        options.add(new SelectOption('MEXICO','Mexico'));

        return options;
    }
 
    public String[] getCountries() {
        return countries;
    }
 
    public void setCountries(String[] countries) {
        this.countries = countries;
    }
}

Hope it helps.
THARUN REDDY BOMMAREDDYTHARUN REDDY BOMMAREDDY
Thank you PasanEeriyagama, do you know what mistake I have done in the above code 
THARUN REDDY BOMMAREDDYTHARUN REDDY BOMMAREDDY
Issue is I have need to replace <apex:selectOptions value="{!objlist}"/> with <apex:selectOptions value="{!sop}"/>
Pasan   EeriyagamaPasan Eeriyagama
Glad you found it, You could mark it answer. Thanks.