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
Ajay Kumar 261Ajay Kumar 261 

Selectoption value is not passing to the controller.

<td> 
  <apex:selectList id="Lcs" value="{!e.selectedLC}" size="1">
    <apex:selectOptions value="{!e.selectedCLC}"/>
    </apex:selectList>                                                                
    </td>

Controller method:
public class WrapperClass{
        public Engagement__c eng {get; set;}
        public List<SelectOption> selectedTrack{get; set;}
        public String selectedNTrack{get; set;}
        public List<SelectOption> selectedCLC{get; set;}
        public id selectedLC{get; set;}
        public WrapperClass(Engagement__c e,List<SelectOption> track, String s,List<SelectOption> clc, id lc){
            selectedTrack = track;
            eng = e;
            selectedNTrack = s;
            selectedCLC = clc;
            selectedLC = lc;
        }
    }
public void getEngagements(){
 
     selectedTrack = '';
     trackOptions = new List<SelectOption>();
     trackOptions.add(new SelectOption('--None--','--None--'));
     Schema.DescribeFieldResult fieldResult = Learning_Community__c.Track__c.getDescribe();
     List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
        
       for( Schema.PicklistEntry f : ple)
       {
          trackOptions.add(new SelectOption(f.getLabel(), f.getValue()));
       }       
     
        Lcoptions = new List<SelectOption>();
        Lcoptions.add(new SelectOption('--Unassigned---','--Unassigned--'));
        for(Learning_Community__c obj :[SELECT Id, Name FROM Learning_Community__c Where Cohort__c=:selectedCohort  ] )
        {
            Lcoptions.add(new SelectOption(obj.Id,obj.Name));
            System.Debug('Lcoptions '+Lcoptions);
        }
        wrapList = new list<WrapperClass>();
        for(Engagement__c eng : [Select id, Name, Site__c, Learning_Community__c,Cohort__c,Learning_Community__r.Name, Learning_Community__r.Track__c from Engagement__c where (Cohort__c=:selectedCohort OR Site__c=:selectedSite) ]){           
           
            wrapList.add(new WrapperClass(eng,trackOptions,null,Lcoptions,null));
            System.debug('wrapList '+wrapList);
        }
 
 }
 public void updateEngagements(){
 try{
 
     list<Engagement__c> enList=new list<Engagement__c>(); 
     list<Learning_Community__c> lcList=new list<Learning_Community__c>(); 
         
     for(WrapperClass wr: wrapList){      
         if(wr.eng.Learning_Community__c!=null){
         Learning_Community__c e= new Learning_Community__c();
         e.id = wr.eng.Learning_Community__c;        
         e.Track__c = wr.selectedNTrack;        
         lcList.add(e);
         }
         System.debug('I am inside wrapper First '+wr.selectedLC); 
         if(wr.selectedLC!='--Unassigned---'){  
         Engagement__c en= new Engagement__c();
         en.id = wr.eng.Id; 
         en.Learning_Community__c= wr.selectedLC; 
         enList.add(en);
         }
                      
     }     
     update lcList;
     //update enList;
     
     }
     catch(exception e){
     ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'Please enter value ' +e.getMessage()));
     }    
 }
 
 public class WrapperClass{
        public Engagement__c eng {get; set;}
        public List<SelectOption> selectedTrack{get; set;}
        public String selectedNTrack{get; set;}
        public List<SelectOption> selectedCLC{get; set;}
        public id selectedLC{get; set;}
        public WrapperClass(Engagement__c e,List<SelectOption> track, String s,List<SelectOption> clc, id lc){
            selectedTrack = track;
            eng = e;
            selectedNTrack = s;
            selectedCLC = clc;
            selectedLC = lc;
        }
    }

When I select the option "Name" from the drop down, I am expecting id to be passed to the controller, however I am not getting the id to the relevant name.

I am getting this error:
Warning:
Please enter value Invalid id: --Unassigned---

Regards,
Ajay
Best Answer chosen by Ajay Kumar 261
Ajay Kumar 261Ajay Kumar 261
Found the issue with wrapperclass variable. converted Id into String.:)