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
satheeshrsksatheeshrsk 

Urgent help: Constructor not defined

Hi All,

 

Getting the following error,can any one help if any idea ?

 

ErrorError: Compile Error: Constructor not defined: [System.SelectOption].<Constructor>(Date, String) at line 15 column 29

 

 

Controller class:

public with sharing class CustomSettingsDemo_CLS{
  public String selectedIso {get;set;}
 

   public CustomSettingsDemo_CLS(ApexPages.StandardController controller) {

    }
    
    public List<selectOption> fqCodes {
        get {
             List<selectOption> options = new List<selectOption>();
 
            for (FiscalQuarters__c fq : FiscalQuarters__c.getAll().values())
                options.add(new SelectOption(fq.CustomFiscalQuarters__c,fq.Name+' - '+fq.CustomFiscalQuarters__c));
            return options;
 
        }
        set;
    }
 
}

 

Using custom setting in the controller class, any help is highly appreciated.

 

 

Thanks in advance,

rsk

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

This is because selectoptions require a string for each of the label and value.  Thus you'll need to convert your date to a formatted string - if you convert the date to a date/time you can format it easily.  Something like the following should do it.

 

DateTime dt=DateTime.newInstance(fq.CustomFiscalQuarters__c, Time.newInstance(12, 0, 0, 0));
String dateStr=dt.format('dd-MM-yy');

 

All Answers

bob_buzzardbob_buzzard

This is because selectoptions require a string for each of the label and value.  Thus you'll need to convert your date to a formatted string - if you convert the date to a date/time you can format it easily.  Something like the following should do it.

 

DateTime dt=DateTime.newInstance(fq.CustomFiscalQuarters__c, Time.newInstance(12, 0, 0, 0));
String dateStr=dt.format('dd-MM-yy');

 

This was selected as the best answer
paddupaddu

Hi Bob,

Thank you very much for your reply.

 

I'm struck how to use this in the selectoptions, it would be great if you can give how to use.

 

 

Best Regards,

 

bob_buzzardbob_buzzard

Here's an example use of selectoption from my blog:

 

http://bobbuzzard.blogspot.co.uk/2012/08/preview-panel.html

satheeshrsksatheeshrsk

Thank you very much Bob. I have converted date into String, which resolved the issue.

 

 

Best Regards,

rsk

 

 

satheeshrsksatheeshrsk

Hi Bob,

 

I'm unable to save the date (in a date filed) as it converted into String. Is there any way to convert this into Date in VF ?, how can i save now.

 

Error:

Value '06-15-2012' cannot be converted from Text to Date.

 

I have used below code in my VF page.

 

<apex:selectList value="{!Opportunity.Quarter__c}" size="1">
                <apex:selectOptions value="{!Items}"/>
 </apex:selectList>

 

 

 

Any help is highly appreciated.

 

Best Regards,

rsk

bob_buzzardbob_buzzard

You'll need to convert that to a date by breaking out the individual components and then instantiating a new date passing those as parameters.