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
Avnit KumarAvnit Kumar 

Getting Error: Compile Error: Illegal assignment from List<System.SelectOption> to List<Id> at line 22 column 1

Hi Developers
I am new in salesforce. Can anyone help me. I'm displaying Accounts in checkbox and their related contacts in selectoption using map. but i'm getting this error

"Error: Compile Error: Illegal assignment from List<System.SelectOption> to List<Id> at line 22 column 1"
My controller page
public class mylasttask{
public list<selectoption> slist{get;set;}
public list<id> clonelist{get;set;}
public map<Account,list<selectoption>> maplist{get;set;}

public mylasttask(){
list<selectoption> slist=new list<selectoption>();
    maplist= new Map<Account, list<selectoption>>();
    list<Account> ac =[select id,name,(select id,name from contacts)from Account];
    
    for(Account a: ac){
    slist=new list<selectoption>();
      for(Contact c: a.contacts){
    slist.add(new selectoption(c.id,c.name));
    maplist.put(a,slist);
   }
  }
  }
  public pagereference clonecase(){
   
  if(slist==true){
clonelist=slist.clone();
insert clonelist;
pagereference p=Apex.CurrentPage();
p.getparameters().put('id',clonelist.id);
p.setRedirect(true);
return p;
}
}
   
    
   }
Thanx in Advance
Manohar kumarManohar kumar

hi Avnit,not sure what you need but i tryied to edit your code.pls have a look and let me know if this helps or not.

public class mylasttask{
public list<selectoption> slist{get;set;}
public list<account> clonelist{get;set;}
public map<Account,list<selectoption>> maplist{get;set;}

public mylasttask(){
list<selectoption> slist=new list<selectoption>();
    maplist= new Map<Account, list<selectoption>>();
    list<Account> ac =[select id,name,(select id,name from contacts)from Account];
    
    for(Account a: ac){
        slist=new list<selectoption>();
            for(Contact c: a.contacts){
                slist.add(new selectoption(c.id,c.name));
                maplist.put(a,slist);
           }
      }
  }
  public pagereference clonecase(){
   
  if(slist.size()>0){
      for(selectoption o:slist) {
        clonelist.add(new account(name = o.getLabel()));
        
        }
        insert clonelist;
        pagereference p=new pagereference('/'+clonelist[0].id);
        p.setRedirect(true);
        return p;
   
    }
    else
        return null;
  
   }
   }


Thanks,

Manohar