+ Start a Discussion
Sharath-learnerSharath-learner 

Select Options

Hi my class is below

 

 

public class SendEmailToCandidates {
    
    public String positionSelected{get; set;}
    //get Positions
    public List<SelectOption> getPositionList()
    {
    List<Selectoption> optns=new List<Selectoption>();       
    List<Position__c> position=[select name,id from Position__c];
            
                for(Position__c pos:position)
                {
                   optns.add(new Selectoption(pos.name,pos.name));
                }   
    System.debug(position);
    return optns;
    
    }

  //constructor
    public SendEmailToCandidates()
    {
    applicantsList=new List<Job_Application__c>();
    positionList=new Position__c();
    }

}

i'm populating positions

but i' m not able to get the positons in the drop down

 

my page is

 

<apex:page controller="SendEmailToCandidates">
<apex:form >
<apex:selectList value="{!positionSelected}" >
<apex:selectOptions value="{!positionList}" >
</apex:selectOptions>
</apex:selectList>
</apex:form>

<apex:page>

 

error is:
Invalid selectOptions found. Use SelectOption type in Apex.

Help me

SkyhSkyh

The answer is in the error.

 

Invalid selectOptions found. Use SelectOption type in Apex.

 

In the class you have SelectOption . In VFP, SelectOptions

 

public List<SelectOption> getPositionList()
    {
    List<Selectoption> optns=new List<Selectoption
>();      

 

 

 

my page is

 

 

 

<apex:page controller="SendEmailToCandidates">
<apex:form >
<apex:selectList value="{!positionSelected}" >
<apex:selectOptions value="{!positionList}" >
</apex:selectOptions>
</apex:selectList>
</apex:form>

 

<apex:page>

 

 

 

Sharath-learnerSharath-learner

Its the syntax for getting list of options in the visual force page

 

https://ap1.salesforce.com/apexpages/apexcomponents.apexp

SkyhSkyh

Try this -

 

public class SendEmailToCandidates {
    
    public String positionSelected{get; set;}
    
    
    //get Positions
    public List<SelectOption> getpositionList()
    {
    List<Selectoption> optns=new List<Selectoption>(); 
   
    List<Position__c> position=[select name,id from Position__c];
            
                for(Position__c pos:position)
                {
                   optns.add(new Selectoption(pos.name,pos.name));
                }   
    System.debug(position);
    return optns;
    
    }

  //constructor
    public SendEmailToCandidates()
    {
    List<Job_Application__c> applicantsList=new List<Job_Application__c>();
    Position__c positionList=new Position__c();
    }

}



//page

<apex:page controller="SendEmailToCandidates">
<apex:form >
    <apex:selectList value="{!positionSelected}" >
        <apex:selectOptions value="{!positionList}" >
        </apex:selectOptions>
    </apex:selectList>
</apex:form>
</apex:page>

Positions in drop down list -

 

SteveBowerSteveBower

What is this line?      positionList=new Position__c();

 

 

Possibly rewrite your controller as:

 

public class SendEmailToCandidates {
    public String positionSelected{get; set;}
    public List<SelectOption> getPositionList()
    {

        List<SelectOption> optns = new List<SelectOption>();

        for (Position__c pos : [select name, id from Position__c]) optns.add(new SelectOption(pos.name,pos.name));
        return optns;
    }

}

 

 

Best, Steve.