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
gdkgdk 

Error for Selectoption: Constructor not defined: for number field

Hi,

 

Error: EnterMarks Compile Error: Constructor not defined: [System.SelectOption].<Constructor>(Decimal, Decimal) at line 11 column 16

 

public List<selectOption> lstR = new List<selectOption>();
    public List<selectOption> getNumber() {
        lstR.add(new selectOption('---None---','---None---'));
    for(Student_Information__c objR:[select Roll_Number__c from Student_Information__c ]){
      lstR.add(new selectOption(objR.Roll_Number__c,objR.Roll_Number__c));
      }
        return lstR;
    }

 

Please help.

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

Selectoptions are made up of a string value and string label, so you can't pass Decimal values in directly.

 

You can convert a decimal to a string using the toPlainString method - something like the underlined below should do the trick:

 

for(Student_Information__c objR:[select Roll_Number__c from Student_Information__c ]){
      lstR.add(new selectOption(objR.Roll_Number__c.toPlainString() ,objR.Roll_Number__c.toPlainString()));
}

 

All Answers

bob_buzzardbob_buzzard

Selectoptions are made up of a string value and string label, so you can't pass Decimal values in directly.

 

You can convert a decimal to a string using the toPlainString method - something like the underlined below should do the trick:

 

for(Student_Information__c objR:[select Roll_Number__c from Student_Information__c ]){
      lstR.add(new selectOption(objR.Roll_Number__c.toPlainString() ,objR.Roll_Number__c.toPlainString()));
}

 

This was selected as the best answer
gdkgdk
thanks it's working