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
❤Code❤Code 

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 ;
        }
        set;
        }

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

             cpOptions.add(cpOptions1);
             cpOptions1.add(cp1.Emp__c);

Regards
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));
}