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
ravi1234.ax1565ravi1234.ax1565 

pick list

hello group,

 

        i have 2 obj enquiry and course i developed 2 pages for both enquiry and course . In enquiry page  i want to have picklist field  'select course',

        but iam not able to execute perfectly.........

         pls go through my below code and  resolve my  prblm

 

      <apex:outputLabel style="font-weight:Bold" value="Select a course :" />
     <apex:SelectList size="1" value="{!lst}">
     <apex:selectOptions value="{!items}"/>
     </apex:SelectList>

    ----------------------------------------------------------------------------------------------

    public List<Course__c> lst{get;set;}

    public Course__C getlst() {
      if (lst == null) {
        lst = [select Name from Course__c];
          }
        return lst;
       }
    }

    public List<SelectOption> getItems(){
           
        List<SelectOption> options = new List<SelectOption>();
        for(Integer i=0; i < lst.size(); i++){
        
            options.add(new SelectOption(lst[i].Name,lst[i].Name));
        }
        
        return options;
    }

 

  iam getting an error that 'un expected token ' at line 'public List<SelectOption> getItems(){'

 

 

note: i dont have a field picklist in my enquiry obj... but i wanrt to display it in vf page is this possible to do

 

 

       pls help me ............

 

 thanks for giving reply in advance

 

     

 

 

ravi1234.ax1565ravi1234.ax1565

hello group i got over the above error

 

 iam getting new one' Return value must be of type: SOBJECT:Course__c' at line return lst;

srinu_SFDCsrinu_SFDC

Ravi,

 

      That because you have declared return type as Course__c instead of List<Course__c>.

public List<Course__C> getlst() {
      if (lst == null) {
        lst = [select Name from Course__c];
          }
        return lst;
       }
    }

 

 

ravi1234.ax1565ravi1234.ax1565

thanks for giving reply srinu

 

               but iam facing 'System.NullPointerException: Attempt to de-reference a null object 

 

Class.Enquiry.getItems: line 70, column 1' at line for(Integer i=0; i < lst.size(); i++)

 

         thanks & regards

             ravi

srinu_SFDCsrinu_SFDC

Ravi,

You can try something like this. Also I suspect your Course__c is not having data, double check that.

 <apex:outputLabel style="font-weight:Bold" value="Select a course :" />
     <apex:SelectList size="1" value="{!course}">
     <apex:selectOptions value="{!items}"/>
     </apex:SelectList>

    public String course {get; set;}
    public List<SelectOption> getItems(){
           
        List<SelectOption> options = new List<SelectOption>();
	List<Course__C> lst = [select Name from Course__c];
	if(1st != null){
		for(Integer i=0; i < lst.size(); i++){
		
		    options.add(new SelectOption(lst[i].Name,lst[i].Name));
		}
        }
        return options;
    }

 

themattythematty

You could save some lines of code and grief by doing this:

    public List<SelectOption> getItems()
{ List<SelectOption> options = new List<SelectOption>(); for(Course__c lst : [select Name from Course__c]) { options.add(new SelectOption(lst.Name,lst.Name)); } return options; }
ravi1234.ax1565ravi1234.ax1565

thanks for giving reply thematty