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
Shwetal DesaiShwetal Desai 

Error for SelectList "Constructor not defined: "

I m trying to create a picklist in my visual force page using select list component...
 
this is my apex code:
 but its give me error: "Constructor not defined: [System.SelectOption].<Constructor>(Id, Double) at line 17 column 29"
what could be the reason??
Apex Code:
public String selectedContact {get;set;}
     
    public List<SelectOption> cardList;
   
    public List<SelectOption> getGiftCard ()
    {
        POS__c posclt = [select Client__c from POS__c where id = :ApexPages.currentPage().getParameters().get('TId')];
        if (contactList == null)
        {
         GiftCertificate__c[] gcard = [select Id,Name,GiftCardNo__c,Remaining__c,ExpiresOn__c
                        from GiftCertificate__c where Purchasedfor__c =: posclt.Client__c and ExpiresOn__c >=:System.today() and Remaining__c>0];           
         cardList = new List<SelectOption>();
         for(GiftCertificate__c gc : gcard)
         {
            cardList.add(new SelectOption(gc.id, gc.GiftCardNo__c));
         }
        }
        return cardList;
    }

 
 
dchasmandchasman
Apex Code does not automatically coerce/convert numbers to strings and your custom field GiftCardNo__c is numeric. This should do the trick:

Code:
cardList.add(new SelectOption(gc.id, String.valueOf(gc.GiftCardNo__c)));

 

Shwetal DesaiShwetal Desai
Thanks Doug,

It works absolutely fine.......

Thanks for the guidance.....
RajgottipoluRajgottipolu

Even i have the same problem.....but im actually passing a string but its not working....

 

Error: Compile Error: Constructor not defined: [System.SelectOption].<Constructor>(String) at line 31 column 25

 

public List<SelectOption> getItems()   

{

    List<SelectOption> options = new List<SelectOption>();   

for( IM_Customer_Account__c i : con.getRecords())   

{   

options.add(new SelectOption(i.name));   

}

return options;   

}

Hary464Hary464

 

Visualforce Error
 


Exception: Constructor not defined: [selectoption].<Constructor>(Id, String)

Error occurred loading controller 'dependentcls' for page hary:dependentpicklist
 

Rajgottipolu wrote:

Even i have the same problem.....but im actually passing a string but its not working....

 

Error: Compile Error: Constructor not defined: [System.SelectOption].<Constructor>(String) at line 31 column 25

 

public List<SelectOption> getItems()   

{

    List<SelectOption> options = new List<SelectOption>();   

for( IM_Customer_Account__c i : con.getRecords())   

{   

options.add(new SelectOption(i.name));   

}

return options;   

}


 

 

 

page:

<apex:page controller="dependentcls" renderAs="pdf" >
<apex:form >

<apex:selectList value="{!selectedAccount}" size="1" >
<apex:selectOptions value="{!options}"/>
<apex:actionSupport event="onchange" action="{!getContacts}" rerender="out" />
</apex:selectList>

<apex:outputpanel id="out">
<apex:selectList size="1" disabled="{!show}" >
<apex:selectOptions value="{!conoptions}"/>
</apex:selectList>
</apex:outputpanel>



<apex:selectCheckboxes layout="pagedirection">
<apex:selectOptions value="{!options}"/>
</apex:selectCheckboxes>


</apex:form>
</apex:page>

 

controller:

 

public with sharing class dependentcls {
public List<SelectOption> options{get; set;}
public List<SelectOption> conoptions{get; set;}
public dependentcls(){
List<Account> lst = [Select id, name from Account];
show = true;
options = new List<SelectOption>();

for(Account acc : lst){
options.add(new SelectOption(acc.Id,acc.name));
}

}
public boolean show {get; set;}
public string selectedAccount{get; set;}
public void getContacts(){
System.debug('-------->'+selectedAccount);
show = true;
List<Contact> lstcon = [Select id, name from Contact where accountid=:selectedAccount];

conoptions = new List<SelectOption>();

for(Contact con : lstcon){
conoptions.add(new SelectOption(con.Id,con.name));
}

if(lstcon.size()>0){
show = false;
}

}

static testmethod void m1(){

Account acc = new Account();
acc.Name ='test';
acc.Phone = '1234';
insert acc;

Contact c = new Contact();
c.lastname ='test';
insert c;

dependentcls obj = new dependentcls();
obj.getcontacts();
}

}

.......