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
chanti kchanti k 

i am getting the below error 's in apex class

Hi,

i am new to apex class , i am getting below errors as well as i put the comments with errors.
Public class fetchdisplayrecords
{
public Contact Con{get; set;}
public string selectedItemValue{get;set;}
public id resc{get;set;}
public fetchdisplayrecords(ApexPages.StandardController controller)
 {
   //acc = [SELECT Name, AccountNumber FROM Account limit 5];
 }
     public List<selectoption> getitems()
     {
     List<Selectoption> opts = new List<Selectoption>();
        opts.add(new selectoption('','--None--'));  // Compile Error: Non-void method might not return a value or might have statement after a return statement.
     }
     
     
     

}



kindly help me on this. i appricated!
Ramssf70Ramssf70
Hi Chanti k ,

In getitems() method  return type is List<selectoption> then you should return LIst<selectoption> you are not retuning anything thats way it is showing error. try this bellow code 
Public class fetchdisplayrecords
{
public Contact Con{get; set;}
public string selectedItemValue{get;set;}
public id resc{get;set;}
public fetchdisplayrecords(ApexPages.StandardController controller)
 {
   //acc = [SELECT Name, AccountNumber FROM Account limit 5];
 }
     public List<selectoption> getitems()
     {
     List<Selectoption> opts = new List<Selectoption>();
        opts.add(new selectoption('','--None--'));  
   return opts;
     }
     
     
     

}


If you don't want to return anything put void as return type  that means you have to write the  getitems() in following way
 
Public class fetchdisplayrecords
{
public Contact Con{get; set;}
public string selectedItemValue{get;set;}
public id resc{get;set;}
public fetchdisplayrecords(ApexPages.StandardController controller)
 {
   //acc = [SELECT Name, AccountNumber FROM Account limit 5];
 }
     public void getitems()
     {
     List<Selectoption> opts = new List<Selectoption>();
        opts.add(new selectoption('','--None--'));  

     }
     
     
     

}
If you have any queries on this feel free to ask me.

Thank you




 
supriya Goresupriya Gore
Hi,
add below statement after line number 13

return opts;

becoz it is non void method you should return somthing and return type of your method is List<Selectoption>,thats why you should return list.
 
Ramssf70Ramssf70
HI chanti,

if your problem  has solved please make it as solved and best answer so that we can try to help others