+ Start a Discussion

Incompatible element type Set<String> for colection of System.SelectOption

How to assign a set to List... I am getting the following error ..

Incompatible element type Set for collection of System.SelectOption.
public List<SelectOption> cpOptions {
        get {
            if (cpOptions== null) {
                cpOptions = new List<SelectOption>();
            return cpOptions ;

    public Set<String> cpOptions1{
        get {
            if (cpOptions1== null) {
                cpOptions1= new Set<String>();
            return cpOptions1;


Antonio ManenteAntonio Manente
Your cpOptions variable is a List of SelectOption objects. Here is the documentation on the SelectOption class ( https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/apex_pages_selectoption.htm ).

You instantiate a SelectOption in this way: 
SelectOption newOption = new SelectOption(String, String);

The first parameter represents the value that will be returned if that item is selected, the second parameter represents what will be displayed on the page. 

So in your case, if you want the value of cp1.Emp__c as your select option you'd have to do:
cpOptions.add(new SelectOption(cp1.Emp__c, cp1.Emp__c));

Or, if you have a set of strings:
for(String s : cpOptions1){
  cpOptions.add(new SelectOption(s, s));