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
Nikhil SomvanshiNikhil Somvanshi 

Error: ListPageClass Compile Error: Constructor not defined: [System.SelectOption].<Constructor>(Boolean, String) at line 18 column 16

Hello People,

 

I am new here to Visualforce and trying to save the following program to show a list Objects based on the selected value from a List. I am getting an Error: ListPageClass Compile Error: Constructor not defined: [System.SelectOption].<Constructor>(Boolean, String) at line 18 column 16.

 

//Class

Public class ListPageClass {

Public ListPageClass()
{
ObjectList = new List<SelectOption>();

}

Public List<SelectOption> ObjectList {get;set;}
Public Boolean AccountCheck {get;set;}
Public Boolean ContactCheck {get;set;}
Public Boolean OpportunityCheck {get;set;}
Public Boolean Checkvalue {get;set;}

Public List<selectoption> getDisplaylist ()
{
 
ObjectList.add(new SelectOption(AccountCheck,'Account'));
ObjectList.add(new SelectOption(ContactCheck,'Contact'));
ObjectList.add(new SelectOption(OpportunityCheck,'Opportunity'));

return ObjectList;
}
}

Visualforce Page:
 
<apex:page controller="ListPageClass" >
<apex:form >
<apex:pageBlock >
<apex:selectList value="{!Checkvalue}">
<apex:selectOption value="{!Displaylist}">
</apex:selectOption>
</apex:selectList>
</apex:pageBlock>
</apex:form>
</apex:page>
Any pointers in the right direction would be gladly appreciated.
Abdul KhatriAbdul Khatri
Here you go

Just made the following change in the code
 
        ObjectList.add(new SelectOption(String.valueOf(AccountCheck),'Account'));
        ObjectList.add(new SelectOption(String.valueOf(ContactCheck),'Contact'));
        ObjectList.add(new SelectOption(String.valueOf(OpportunityCheck),'Opportunity'));

Here is the full code.
public class ListPageClass {
    
   Public ListPageClass()
	{
		ObjectList = new List<SelectOption>();
    }
    
    Public List<SelectOption> ObjectList { get; set;}
    Public Boolean AccountCheck {get;set;}
    Public Boolean ContactCheck {get;set;}
    Public Boolean OpportunityCheck {get;set;}
    Public Boolean Checkvalue {get;set;}      

    Public List<selectoption> getDisplaylist ()
    {
        ObjectList.add(new SelectOption(String.valueOf(AccountCheck),'Account'));
        ObjectList.add(new SelectOption(String.valueOf(ContactCheck),'Contact'));
        ObjectList.add(new SelectOption(String.valueOf(OpportunityCheck),'Opportunity'));

    	return ObjectList;
    }
}

 
Maharajan CMaharajan C
Hi Nikhil,

Are you are try like this:

<!-- Page: -->
<apex:page controller="ListPageClass">
    <apex:form >            
        
        <apex:selectList id="selected_list" value="{!Checkvalue}" required="false" size="1">
                  <apex:selectOptions value="{!Displaylist}"/>
            <apex:actionSupport event="onchange" reRender="Details" action="{!find}"/>
        </apex:selectList>
        <br/>
        <apex:panelGroup >        
            <apex:outputPanel id="Details">            
                The value you Selected : {!SelectedValue}            
            </apex:outputPanel>
        </apex:panelGroup>
         
    </apex:form>
</apex:page> 


//Class

Public class ListPageClass{

Public ListPageClass()
{

}

Public List<SelectOption> ObjectList {get;set;}

Public String Checkvalue {get;set;}
Public String SelectedValue {get;set;}

Public List<selectoption> getDisplaylist ()
{
ObjectList = new List<SelectOption>(); 
ObjectList.add(new SelectOption('AccountCheck','Account'));
ObjectList.add(new SelectOption('ContactCheck','Contact'));
ObjectList.add(new SelectOption('OpportunityCheck','Opportunity'));

return ObjectList;
}

Public Void find()
{
 SelectedValue  = Checkvalue;
}
}

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_selectOptions.htm

Can you please Let me know if it helps or not!!!

If it helps don't forget to mark this as a best answer!!!


Thanks,
Raj