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
Vadivel MuruganVadivel Murugan 

Pick List Value in Wrapper Class

public class sparedetails
{
    public Spare_Details__c sparedet{get;set;}
    public String sparedetail {get;set;}
    public String asparedetail {get;set;}
    public Boolean check{get;set;}
    public Boolean pcheck{get;set;}
    public Engineer_Checklist__c ec{get;set;}
    public List<sparts> ssList{get;set;}    
    
    public class sparts{
        public List<SelectOption> sdetail{get;set;}
        public List<selectOption> sdetaildep{get;set;}
        public integer qty{get;set;}
        public String aparts{get;set;}
        public sparts(){
            this.sdetail=sdetails();  // Here how to call, i have call this type error in "Invalid Field"
            this.sdetaildep=getasparedetails(); // Same as here
            this.qty=0;
            this.aparts='';
        }
    }
    
    public sparedetails(ApexPages.StandardController controller) {
    check=false;
    pcheck=false;
    //ec=[select id,Engineer__r.name from Engineer_Checklist__c where id=:apexpages.currentpage().getparameters().get('id')];
    //sparedet = [select aspareparts__c,qty__c,spareparts__c,sparepartsinp__c from Spare_Details__c where id=:apexpages.currentpage().getparameters().get('id')];
    ssList=new List<sparts>();
    }
    
    public PageReference addrow(){
             
        ssList.add(new sparts());
        return null;
    }
    public void removeRow(){
        Integer count=Integer.valueOf(apexpages.currentpage().getparameters().get('index'));
        ssList.remove(count);
    }
    
    public List<SelectOption> sdetails()
    {
        List<SelectOption> spd = new List<SelectOption>();
        
        spd.add(new SelectOption('None','--- None ---')); 
        spd.add(new SelectOption('sd','Smoke Detector')); 
        spd.add(new SelectOption('hd','Heat Detector')); 
        spd.add(new SelectOption('msd','Multi Sensor Detector')); 
        spd.add(new SelectOption('bs','Base')); 
        spd.add(new SelectOption('ss','Smoke Sounder')); 
        spd.add(new SelectOption('hs','Heat Sounder')); 
        spd.add(new SelectOption('bc','Breakglass Callpoint')); 
        spd.add(new SelectOption('tk','Test Keys')); 
        spd.add(new SelectOption('rg','Replacement Glass')); 
        spd.add(new SelectOption('bc','Breakglass Cover')); 
        spd.add(new SelectOption('es','Electronic Sounder')); 
        spd.add(new SelectOption('fb','Fire Bell')); 
        spd.add(new SelectOption('bec','Beacon')); 
        spd.add(new SelectOption('dr','Door Release')); 
        spd.add(new SelectOption('pc','Printer Consumables')); 
        spd.add(new SelectOption('slab','SLA Battery')); 
        spd.add(new SelectOption('nic','Nicad Hi-Temp Cells X'));
        spd.add(new SelectOption('anic','Additional Nicad Hi-Temp Cells X'));
        spd.add(new SelectOption('el','Emergency Lights'));
        spd.add(new SelectOption('ael','Additional Emergency Lights'));
        spd.add(new SelectOption('elt','EL Tube'));
        spd.add(new SelectOption('aelt','Additional EL Tube'));
        spd.add(new SelectOption('ftt','4,6,8FT Tube'));
        spd.add(new SelectOption('lbs','Log Book Supplied - Qty'));
        spd.add(new SelectOption('oth','Other'));        
        return spd;  
    } 
    
    public List<SelectOption> getasparedetails()
    {
        List<SelectOption> spdl = new List<SelectOption>();   
        
        if(sparedetail  == 'None'){
        check=false;
        }
         
        if(sparedetail  == 'sd' || sparedetail  == 'hd' || sparedetail  == 'ss' || sparedetail  == 'hs' || sparedetail  == 'es' || sparedetail  == 'bec'){
        
        pcheck=true;
        
            spdl.add(new SelectOption('at','ADT'));
            spdl.add(new SelectOption('ad','Apollo Discovery'));
            spdl.add(new SelectOption('as65','Apollo S65'));
            spdl.add(new SelectOption('ax95','Apollo XP95'));
            spdl.add(new SelectOption('aut','Autronica'));
            spdl.add(new SelectOption('ed','EDA'));
            spdl.add(new SelectOption('em','EMS'));
            spdl.add(new SelectOption('get','Gent'));
            spdl.add(new SelectOption('hoc','Hochiki'));
            spdl.add(new SelectOption('nitt','Nittan'));
            spdl.add(new SelectOption('not','Notifier'));
            spdl.add(new SelectOption('men','Menvier'));
            spdl.add(new SelectOption('pro','Protec'));
            spdl.add(new SelectOption('raf','Rafiki'));
            spdl.add(new SelectOption('sys','Systemsensor'));
            spdl.add(new SelectOption('zit','Ziton'));
            spdl.add(new SelectOption('oth','Other'));
        }        
        if(sparedetail  == 'msd'){
        }        
        if(sparedetail  == 'bs'){        
        pcheck=true;
            spdl.add(new SelectOption('db','Detector Base'));
            spdl.add(new SelectOption('dob','Diode Base'));
        }        
        if(sparedetail  == 'bc'){   
        pcheck=true;     
            spdl.add(new SelectOption('at','ADT'));
            spdl.add(new SelectOption('ad','Apollo Discovery'));
            spdl.add(new SelectOption('as65','Apollo S65'));
            spdl.add(new SelectOption('ax95','Apollo XP95'));
            spdl.add(new SelectOption('aut','Autronica'));
            spdl.add(new SelectOption('ed','EDA'));
            spdl.add(new SelectOption('em','EMS'));
            spdl.add(new SelectOption('get','Gent'));
            spdl.add(new SelectOption('hoc','Hochiki'));
            spdl.add(new SelectOption('nitt','Nittan'));
            spdl.add(new SelectOption('not','Notifier'));
            spdl.add(new SelectOption('men','Menvier'));
            spdl.add(new SelectOption('pro','Protec'));
            spdl.add(new SelectOption('raf','Rafiki'));
            spdl.add(new SelectOption('sys','Systemsensor'));
            spdl.add(new SelectOption('zit','Ziton'));
            spdl.add(new SelectOption('wp','Waterproof'));
            spdl.add(new SelectOption('oth','Other'));
        }        
        if(sparedetail  == 'tk' || sparedetail  == 'rg' || sparedetail  == 'bc' || sparedetail  == 'fb' || sparedetail  == 'dr' || sparedetail  == 'pc' || sparedetail  == 'ftt' || sparedetail  == 'lbs' || sparedetail  == 'oth'){
            check = true;
            pcheck=false;
        }        
        if(sparedetail  == 'slab'){
        pcheck=true;        
            spdl.add(new SelectOption('1.2a','12v 1.2Ah'));
            spdl.add(new SelectOption('12a','12v 12Ah'));
            spdl.add(new SelectOption('17a','12v 17Ah'));
            spdl.add(new SelectOption('2.1a','12v 2.1Ah'));
            spdl.add(new SelectOption('2.8a','12v 2.8Ah'));
            spdl.add(new SelectOption('24a','12v 24Ah'));
            spdl.add(new SelectOption('3.2a','12v 3.2Ah'));
            spdl.add(new SelectOption('7a','12v 7Ah'));
            spdl.add(new SelectOption('10a','6v 10Ah'));
            spdl.add(new SelectOption('ed','EDA'));
            spdl.add(new SelectOption('es','EMS'));
        }        
        if(sparedetail  == 'nic' || sparedetail  == 'anic'){     
        pcheck=true;   
            spdl.add(new SelectOption('1c','1 Cell'));
            spdl.add(new SelectOption('2c','2 Cell'));
            spdl.add(new SelectOption('3c','3 Cell'));
            spdl.add(new SelectOption('4c','4 Cell'));
            spdl.add(new SelectOption('5c','5 Cell'));
            spdl.add(new SelectOption('oth','Other'));
        }        
        if(sparedetail  == 'el' || sparedetail  == 'ael'){  
        pcheck=true;      
            spdl.add(new SelectOption('16w','16w 2D'));
            spdl.add(new SelectOption('28w','28w 2D'));
            spdl.add(new SelectOption('38w','38w 2D'));
            spdl.add(new SelectOption('2d','28w 2D c/w P/c'));
            spdl.add(new SelectOption('8w','8w Bulkhead'));
            spdl.add(new SelectOption('eb','Exit Box'));
            spdl.add(new SelectOption('ld','LED'));
            spdl.add(new SelectOption('ldb','LED Bulkhead'));
            spdl.add(new SelectOption('leb','LED Exit box'));
            spdl.add(new SelectOption('lgd','Legend'));
            spdl.add(new SelectOption('tb','Twinspot Beam'));
        }        
        if(sparedetail  == 'elt' || sparedetail  == 'aelt'){   
        pcheck=true;     
            spdl.add(new SelectOption('4w','4 Watt Tube rep.'));
            spdl.add(new SelectOption('6w','6 Watt Tube rep.'));
            spdl.add(new SelectOption('8w','8 Watt Tube rep.'));
            spdl.add(new SelectOption('2d','2D Lamp/Biax'));
        }    
          
        return spdl;
    }       
}


Here how to call my picklist method in wrapper class.
 
Shrikant BagalShrikant Bagal
Please change following lines:
 
this.sdetail=sdetails();  // Here how to call, i have call this type error in "Invalid Field"
            this.sdetaildep=getasparedetails(); // Same as here
TO
this.sdetail = new List<SelectOption>();
 this.sdetaildep = new List<SelectOption>();
Hope this help you!!!

 
Vadivel MuruganVadivel Murugan
public class sparedetails
{
    public Spare_Details__c sparedet{get;set;}
    public String sparedetail {get;set;}
    public String asparedetail {get;set;}
    public Boolean check{get;set;}
    public Boolean pcheck{get;set;}
    public Engineer_Checklist__c ec{get;set;}
    public List<sparts> ssList{get;set;}    
    
    public class sparts{
    sparedetails o;
        public List<SelectOption> sdetail{get;set;}
        public List<selectOption> sdetaildep{get;set;}
        public integer qty{get;set;}
        public String aparts{get;set;}
        public sparts(){
        this.sdetail=new List<SelectOption>();
        this.sdetaildep=new List<SelectOption>();
            this.sdetail=sdetails();
            this.sdetaildep=getasparedetails();
            this.qty=0;
            this.aparts='';
        }
        public List<SelectOption> sdetails()
        {
        
        List<SelectOption> spd= new List<SelectOption>();
        
       spd.add(new SelectOption('None','--- None ---')); 
       spd.add(new SelectOption('sd','Smoke Detector')); 
       spd.add(new SelectOption('hd','Heat Detector')); 
       spd.add(new SelectOption('msd','Multi Sensor Detector')); 
       spd.add(new SelectOption('bs','Base')); 
       spd.add(new SelectOption('ss','Smoke Sounder')); 
       spd.add(new SelectOption('hs','Heat Sounder')); 
       spd.add(new SelectOption('bc','Breakglass Callpoint')); 
       spd.add(new SelectOption('tk','Test Keys')); 
       spd.add(new SelectOption('rg','Replacement Glass')); 
       spd.add(new SelectOption('bc','Breakglass Cover')); 
       spd.add(new SelectOption('es','Electronic Sounder')); 
       spd.add(new SelectOption('fb','Fire Bell')); 
       spd.add(new SelectOption('bec','Beacon')); 
       spd.add(new SelectOption('dr','Door Release')); 
       spd.add(new SelectOption('pc','Printer Consumables')); 
       spd.add(new SelectOption('slab','SLA Battery')); 
       spd.add(new SelectOption('nic','Nicad Hi-Temp Cells X'));
       spd.add(new SelectOption('anic','Additional Nicad Hi-Temp Cells X'));
       spd.add(new SelectOption('el','Emergency Lights'));
       spd.add(new SelectOption('ael','Additional Emergency Lights'));
       spd.add(new SelectOption('elt','EL Tube'));
       spd.add(new SelectOption('aelt','Additional EL Tube'));
       spd.add(new SelectOption('ftt','4,6,8FT Tube'));
       spd.add(new SelectOption('lbs','Log Book Supplied - Qty'));
       spd.add(new SelectOption('oth','Other'));        
        return spd;  
    }
    
      public List<SelectOption> getasparedetails()
    {
        List<SelectOption> spdl = new List<SelectOption>(); 
        system.debug('>>>>val>>>>'+o.sparedetail);  
        
        if(o.sparedetail  == 'None'){
        o.check=false;
        }
         
        if(o.sparedetail  == 'sd' || o.sparedetail  == 'hd' || o.sparedetail  == 'ss' || o.sparedetail  == 'hs' || o.sparedetail  == 'es' || o.sparedetail  == 'bec'){
        
        o.pcheck=true;
        
            spdl.add(new SelectOption('at','ADT'));
            spdl.add(new SelectOption('ad','Apollo Discovery'));
            spdl.add(new SelectOption('as65','Apollo S65'));
            spdl.add(new SelectOption('ax95','Apollo XP95'));
            spdl.add(new SelectOption('aut','Autronica'));
            spdl.add(new SelectOption('ed','EDA'));
            spdl.add(new SelectOption('em','EMS'));
            spdl.add(new SelectOption('get','Gent'));
            spdl.add(new SelectOption('hoc','Hochiki'));
            spdl.add(new SelectOption('nitt','Nittan'));
            spdl.add(new SelectOption('not','Notifier'));
            spdl.add(new SelectOption('men','Menvier'));
            spdl.add(new SelectOption('pro','Protec'));
            spdl.add(new SelectOption('raf','Rafiki'));
            spdl.add(new SelectOption('sys','Systemsensor'));
            spdl.add(new SelectOption('zit','Ziton'));
            spdl.add(new SelectOption('oth','Other'));
        }        
              
        if(o.sparedetail  == 'bs'){        
        o.pcheck=true;
            spdl.add(new SelectOption('db','Detector Base'));
            spdl.add(new SelectOption('dob','Diode Base'));
        }        
        if(o.sparedetail  == 'bc'){   
        o.pcheck=true;     
            spdl.add(new SelectOption('at','ADT'));
            spdl.add(new SelectOption('ad','Apollo Discovery'));
            spdl.add(new SelectOption('as65','Apollo S65'));
            spdl.add(new SelectOption('ax95','Apollo XP95'));
            spdl.add(new SelectOption('aut','Autronica'));
            spdl.add(new SelectOption('ed','EDA'));
            spdl.add(new SelectOption('em','EMS'));
            spdl.add(new SelectOption('get','Gent'));
            spdl.add(new SelectOption('hoc','Hochiki'));
            spdl.add(new SelectOption('nitt','Nittan'));
            spdl.add(new SelectOption('not','Notifier'));
            spdl.add(new SelectOption('men','Menvier'));
            spdl.add(new SelectOption('pro','Protec'));
            spdl.add(new SelectOption('raf','Rafiki'));
            spdl.add(new SelectOption('sys','Systemsensor'));
            spdl.add(new SelectOption('zit','Ziton'));
            spdl.add(new SelectOption('wp','Waterproof'));
            spdl.add(new SelectOption('oth','Other'));
        }        
        if(o.sparedetail  == 'tk' || o.sparedetail  == 'rg' || o.sparedetail  == 'bc' || o.sparedetail  == 'fb' || o.sparedetail  == 'dr' || o.sparedetail  == 'pc' || o.sparedetail  == 'ftt' || o.sparedetail  == 'lbs' || o.sparedetail  == 'msd' || o.sparedetail  == 'oth'){
            o.check = true;
            o.pcheck=false;
        }        
        if(o.sparedetail  == 'slab'){
        o.pcheck=true;        
            spdl.add(new SelectOption('1.2a','12v 1.2Ah'));
            spdl.add(new SelectOption('12a','12v 12Ah'));
            spdl.add(new SelectOption('17a','12v 17Ah'));
            spdl.add(new SelectOption('2.1a','12v 2.1Ah'));
            spdl.add(new SelectOption('2.8a','12v 2.8Ah'));
            spdl.add(new SelectOption('24a','12v 24Ah'));
            spdl.add(new SelectOption('3.2a','12v 3.2Ah'));
            spdl.add(new SelectOption('7a','12v 7Ah'));
            spdl.add(new SelectOption('10a','6v 10Ah'));
            spdl.add(new SelectOption('ed','EDA'));
            spdl.add(new SelectOption('es','EMS'));
        }        
        if(o.sparedetail  == 'nic' || o.sparedetail  == 'anic'){     
        o.pcheck=true;   
            spdl.add(new SelectOption('1c','1 Cell'));
            spdl.add(new SelectOption('2c','2 Cell'));
            spdl.add(new SelectOption('3c','3 Cell'));
            spdl.add(new SelectOption('4c','4 Cell'));
            spdl.add(new SelectOption('5c','5 Cell'));
            spdl.add(new SelectOption('oth','Other'));
        }        
        if(o.sparedetail  == 'el' || o.sparedetail  == 'ael'){  
        o.pcheck=true;      
            spdl.add(new SelectOption('16w','16w 2D'));
            spdl.add(new SelectOption('28w','28w 2D'));
            spdl.add(new SelectOption('38w','38w 2D'));
            spdl.add(new SelectOption('2d','28w 2D c/w P/c'));
            spdl.add(new SelectOption('8w','8w Bulkhead'));
            spdl.add(new SelectOption('eb','Exit Box'));
            spdl.add(new SelectOption('ld','LED'));
            spdl.add(new SelectOption('ldb','LED Bulkhead'));
            spdl.add(new SelectOption('leb','LED Exit box'));
            spdl.add(new SelectOption('lgd','Legend'));
            spdl.add(new SelectOption('tb','Twinspot Beam'));
        }        
        if(o.sparedetail  == 'elt' || o.sparedetail  == 'aelt'){   
        o.pcheck=true;     
            spdl.add(new SelectOption('4w','4 Watt Tube rep.'));
            spdl.add(new SelectOption('6w','6 Watt Tube rep.'));
            spdl.add(new SelectOption('8w','8 Watt Tube rep.'));
            spdl.add(new SelectOption('2d','2D Lamp/Biax'));
        }   
        
        if(o.sparedetail  == null || o.sparedetail  == '') {
            spdl.add(new SelectOption('non','----None----'));
        }
          spdl.add(new SelectOption('at','ADT'));
            spdl.add(new SelectOption('ad','Apollo Discovery'));
            spdl.add(new SelectOption('as65','Apollo S65'));
            spdl.add(new SelectOption('ax95','Apollo XP95'));
            spdl.add(new SelectOption('aut','Autronica'));
            spdl.add(new SelectOption('ed','EDA'));
            spdl.add(new SelectOption('em','EMS'));
            spdl.add(new SelectOption('get','Gent'));
            spdl.add(new SelectOption('hoc','Hochiki'));
            spdl.add(new SelectOption('nitt','Nittan'));
            spdl.add(new SelectOption('not','Notifier'));
            spdl.add(new SelectOption('men','Menvier'));
            spdl.add(new SelectOption('pro','Protec'));
            spdl.add(new SelectOption('raf','Rafiki'));
            spdl.add(new SelectOption('sys','Systemsensor'));
            spdl.add(new SelectOption('zit','Ziton'));
            spdl.add(new SelectOption('oth','Other'));
        return spdl;
    } 
 }
    
    public sparedetails(ApexPages.StandardController controller) {
    check=false;
    pcheck=false;
    //ec=[select id,Engineer__r.name from Engineer_Checklist__c where id=:apexpages.currentpage().getparameters().get('id')];
    //sparedet = [select aspareparts__c,qty__c,spareparts__c,sparepartsinp__c from Spare_Details__c where id=:apexpages.currentpage().getparameters().get('id')];
    ssList=new List<sparts>();
    }
    
    public PageReference addrow(){
         ssList.add(new sparts());
        return null;
    }
    public void removeRow(){
        Integer count=Integer.valueOf(apexpages.currentpage().getparameters().get('index'));
        ssList.remove(count);
    }
   
         
}

To came this Error:

Visualforce ErrorHelp for this Page
System.NullPointerException: Attempt to de-reference a null object
Error is in expression '{!addrow}' in component <apex:commandButton> in page sparedetails: Class.sparedetails.sparts.getasparedetails: line 62, column 1
Class.sparedetails.sparts.<init>: line 21, column 1
Class.sparedetails.addrow: line 199, column 1
Class.sparedetails.sparts.getasparedetails: line 62, column 1
Class.sparedetails.sparts.<init>: line 21, column 1
Class.sparedetails.addrow: line 199, column 1