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
hareeshnhareeshn 

how to get selected item from selectList and passing to controller

am unable to get selected item from selectlist and passing to controler  bellow is my code please help me on this

vf page
--------------------------------------------------------------
<apex:page standardController="user"   extensions="Jobformation1usercon">
       <apex:form >
       <apex:pageBlock >
         <apex:pageBlockSection >
           <apex:pageBlockTable value="{!accwraplist }" var="accwrapref">
       
      
       <apex:column headerValue="Job Name" value="{!accwrapref.acc.name}" />      
        <apex:column headerValue="User" >
           <apex:selectList size="1"  rendered="true"  value="{!a}">
             <apex:selectOptions value="{!Value}" >
                               
               </apex:selectOptions>
                 </apex:selectList>
         </apex:column>
          <apex:column headerValue="Share a Record" >
                          <apex:commandLink action="{!manualShareRead}" value="Share">
                     <apex:param name="id" value="{!accwrapref.acc.id}"/>
          </apex:commandLink>
                   </apex:column>
            </apex:pageBlockTable>
         </apex:pageBlockSection>
       </apex:pageBlock>
      </apex:form>
</apex:page>
----------------------------------------------------------------------------
apex controler
--------------------------------------------------------------
public class Jobformation1usercon
{

         List<user> PGList= new List<user>(); 
         public List<job__c> jl {get;set;}
         public user gp {get;set;}
         public boolean nojb{get;set;}
         public String a  {get;set;}
         public List<job__C> acclist {get;set;}
         public List<Accountwraper> accwraplist {get;set;}
         public List<group> lstgroup {get;set;}
  


        public Jobformation1usercon(ApexPages.StandardController controller)
       
       {
    
        accwraplist =new List<Accountwraper>();
        acclist=[select id,name from job__c];
        Accountwraper  objwrap;
        for(job__c objacc:acclist)
        {
        objwrap=new Accountwraper();
        objwrap.acc=objacc;
        system.debug('acclist value'+acclist);
        accwraplist.add(objwrap);
        system.debug(' objwrap value '+objwrap);
        }
       
        //
    }
     public List<SelectOption> getValue()
     {  
         List<SelectOption> option = new List<SelectOption>();
            
        for(user gp: [Select Name From  user  ])
         {
         
             option.add(new SelectOption(gp.id,gp.Name));
             system.debug('option value is '+option);
            
         }
         return option;     
    }
                
       public PageReference manualShareRead()
           {
             
               Id id = System.currentPageReference().getParameters().get('id');
               system.debug('Id Value is'+id);
               system.debug('aaaaaaaaaaaaaaaaaaaaaa'+a);
               PGList = [select id from user where name=:a];
               system.debug('PGList value is'+PGList);
               Job__Share jobShr  = new Job__Share(); 
               jobShr.ParentId = id;
               jobShr.UserOrGroupId = PGList[0].id;
               jobShr.AccessLevel = 'Read';
               jobShr.RowCause = Schema.Job__Share.RowCause.Manual;
              
             Database.SaveResult sr = Database.insert(jobShr,false);
              system.debug('sr value is'+sr);
      
             if(sr.isSuccess())
            {
               system.debug('sr.isSuccess() value:'+sr.isSuccess());
                  system.debug('if sr.isSuccess() block');
               PageReference nextpage = new PageReference('/apex/CustomTeam?id='+id);
             
                return nextpage;
               }
           else {
                  system.debug('inner else sr.isSuccess() block');
                     Database.Error err = sr.getErrors()[0];
                     if(err.getStatusCode() == StatusCode.FIELD_FILTER_VALIDATION_EXCEPTION  && 
                     err.getMessage().contains('AccessLevel')){
                      system.debug(' iner if sr.isSuccess() block');
                      PageReference nextpage = new PageReference('/apex/CustomTeam?id='+id);
                return nextpage;
            }
             else
             {
                      system.debug('outer else sr.isSuccess() block');
               PageReference nextpage = new PageReference('/apex/CustomTeam?id='+id);
                    return nextpage;
               }
             }
         
         }
  
  
        class Accountwraper
        {
        public job__c acc { get;set;}
        public boolean selected { get;set;}
       
        }
     }
hitesh90hitesh90
Hi hareesh,

see below changed code(In Bold) for selected user to get in controller.


Visualforce Page:
<apex:page standardController="user"   extensions="Jobformation1usercon">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection >
                <apex:pageBlockTable value="{!accwraplist }" var="accwrapref">   
                    <apex:column headerValue="Job Name" value="{!accwrapref.acc.name}" />     
                    <apex:column headerValue="User" >
                        <apex:selectList size="1"  rendered="true"  value="{!accwrapref.strselectedUser}">
                            <apex:selectOptions value="{!Value}" >           
                            </apex:selectOptions>
                        </apex:selectList>
                    </apex:column>
                    <apex:column headerValue="Share a Record" >
                        <apex:commandLink action="{!manualShareRead}" value="Share">
                            <apex:param name="id" value="{!accwrapref.acc.id}"/>
                        </apex:commandLink>
                    </apex:column>
                </apex:pageBlockTable>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>


Apex Class:
public class Jobformation1usercon{
List<user> PGList= new List<user>();
public List<job__c> jl {get;set;}
public user gp {get;set;}
public boolean nojb{get;set;}
public String a  {get;set;}
public List<job__C> acclist {get;set;}
public List<Accountwraper> accwraplist {get;set;}
public List<group> lstgroup {get;set;}
public Jobformation1usercon(ApexPages.StandardController controller){
  accwraplist =new List<Accountwraper>();
  acclist=[select id,name from job__c];
  Accountwraper  objwrap;
  for(job__c objacc:acclist){
   objwrap=new Accountwraper();
   objwrap.acc=objacc;
   system.debug('acclist value'+acclist);
   accwraplist.add(objwrap);
   system.debug(' objwrap value '+objwrap);
  } 
}
public List<SelectOption> getValue(){ 
  List<SelectOption> option = new List<SelectOption>();
  for(user gp: [Select Name From  user  ]){
   option.add(new SelectOption(gp.id,gp.Name));
   system.debug('option value is '+option);
  }
  return option;    
}
               
public PageReference manualShareRead(){
  for(Accountwraper ac: accwraplist){
            system.debug('############'+strselectedUser);
        }

 
  Id id = System.currentPageReference().getParameters().get('id');
  system.debug('Id Value is'+id);
  system.debug('aaaaaaaaaaaaaaaaaaaaaa'+a);
  PGList = [select id from user where name=:a];
  system.debug('PGList value is'+PGList);
  Job__Share jobShr  = new Job__Share();
  jobShr.ParentId = id;
  jobShr.UserOrGroupId = PGList[0].id;
  jobShr.AccessLevel = 'Read';
  jobShr.RowCause = Schema.Job__Share.RowCause.Manual;
  Database.SaveResult sr = Database.insert(jobShr,false);
  system.debug('sr value is'+sr);
  if(sr.isSuccess()){
   system.debug('sr.isSuccess() value:'+sr.isSuccess());
   system.debug('if sr.isSuccess() block');
   PageReference nextpage = new PageReference('/apex/CustomTeam?id='+id);
   return nextpage;
  }else{
   system.debug('inner else sr.isSuccess() block');
   Database.Error err = sr.getErrors()[0];
   if(err.getStatusCode() == StatusCode.FIELD_FILTER_VALIDATION_EXCEPTION  && err.getMessage().contains('AccessLevel')){
    system.debug(' iner if sr.isSuccess() block');
    PageReference nextpage = new PageReference('/apex/CustomTeam?id='+id);
    return nextpage;
   }else{
    system.debug('outer else sr.isSuccess() block');
    PageReference nextpage = new PageReference('/apex/CustomTeam?id='+id);
    return nextpage;
   }
  }

}
class Accountwraper{
  public job__c acc { get;set;}
  public boolean selected { get;set;}
  public string strselectedUser { get;set;}
}
}

Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator & Advanced Administrator & Sales cloud consultant
Email :- hiteshpatel.aspl@gmail.com
My Blog:- http://mrjavascript.blogspot.in/