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
oorellanooorellano 

Conversion Error setting value for checkboxes

Hi, I'm getting this error on my VF page after selecting some of the checkboxes: Conversion Error setting value 'Case Task' for '#{objectTypes}', .

 

And don't know why =S

 

On my VF Page I have:

 

<apex:selectCheckboxes value="{!objectTypes}">
        <apex:selectOptions value="{!objectTypesOptions}"/>
</apex:selectCheckboxes>

 

And on my Controller,  objectTypes is a List<String> and objectTypesOptions is a List<SelectOption>.

 

Any ideas?

Thanks in advance,

Orlando

Best Answer chosen by Admin (Salesforce Developers) 
oorellanooorellano

Don't pay me atention. I found my mistake.

I wasn't initializating objectTypes list, I thought that declaring objectTypes like a property {get;set;} I didn't need to initialize it, but yes.

 

Regards,

Orlando

All Answers

oorellanooorellano

Don't pay me atention. I found my mistake.

I wasn't initializating objectTypes list, I thought that declaring objectTypes like a property {get;set;} I didn't need to initialize it, but yes.

 

Regards,

Orlando

This was selected as the best answer
aamDevaamDev

Hi Orlando,

 

I could really use your help. I am receiving a similar error when retrieving values from a multi select list. I keep reading posts about the need to initialize the list, but I keep getting an error. Here's what's in my controller:

 

 

public List<Id> productionNumbers { get; set; }

public List<Id> selectedNumbers { get; set; }

 

 

Here's my VF:

 

 

<apex:outputLabel for="productionNumbers" value="Available Production No(s):" /><br />
<apex:selectList id="productionNumbers" styleClass="firstSelect" value="{!productionNumbers}" multiselect="true" size="4">
<apex:selectOptions value="{!productionOptions}" />
</apex:selectList>

<apex:outputLabel for="selectedNumbers" value="Selected Production No(s):" /><br />
<apex:selectList id="selectedNumbers" styleClass="secondSelect" value="{!selectedNumbers}" multiselect="true" size="4">
<apex:selectOptions value="{!selectedOptions}" />
</apex:selectList>

 

I get a "Duplicate Variable" error in Eclipse when I try to initialize a list like:

 

 

List<Id> productionNumbers = new List<Id>();

 

I feel I'm overlooking something very basic. This little but crucial piece is keeping me from completing a much needed piece of functionality. Thanks in advance!

 

 

oorellanooorellano

Hi,

 

Yes, the problem is you're declaring that list twice,

1 - public List<Id> productionNumbers { get; set; }

2 - List<Id> productionNumbers = new List<Id>();

 

So in your constructor controller, you need to initialize that list like this: productionNumbers = new List<Id>();

 

Regards,

Orlando

 

 

 

aamDevaamDev

Thank you Orlando, that fixed my Conversion Error. I really appreciate your speedy reply.

 

Unfortunately, now I'm receiving a "Validation Error: Value is not valid" error. I have two mutli select lists that I'd like my users to be able to pass options back and forth (using jQuery). When I move values between the boxes and perform my desired action, I receive the Validation Error. I really don't know why it would give me this error, it was clear before that I was returning the desired values.

  

I know that I'm asking for more than help with my Conversion Error issue, but any assistance you could give would be greatly appreciated.

  

Here's my VF:

  

<apex:form id="productionAdd" rendered="{!(i > 0)}">
	<apex:pageBlock >
		<apex:pageMessages />
		<apex:pageBlockButtons location="bottom">
			<apex:commandButton value="Save" action="{!save}"/>
	         </apex:pageBlockButtons>
         		<apex:pageBlockSection id="productionSection" title="Select Production Number(s) for Membership">
            		<apex:outputText value="There are currently none to choose from" rendered="{!(j = 0)}" />
	            	<apex:outputPanel styleClass="pageSection" layout="block" rendered="{!(j > 0)}">
            			<div class="section">
					<apex:outputLabel for="productionNumbers" value="Available Production No(s):" /><br />
					<apex:selectList id="productionNumbers" styleClass="firstSelect" value="{!productionNumbers}" multiselect="true" size="4">
						<apex:selectOptions value="{!productionOptions}" />
					</apex:selectList>
				</div>
				<div class="section">
					<label class="lbl" for="add">Add</label>
					<a id="add"><img src="/img/arrow_rt.gif" alt="add" title="Add" /></a><br />
					<a id="remove"><img src="/img/arrow_lt.gif" alt="remove" title="Remove" /></a><br />
				</div>
				<div class="section">
					<apex:outputLabel for="selectedNumbers" value="Selected Production No(s):" /><br />
					<apex:selectList id="selectedNumbers" styleClass="secondSelect" value="{!selectedNumbers}" multiselect="true" size="4">
						<apex:selectOptions value="{!selectedOptions}" />
					</apex:selectList>
				</div>
			</apex:outputPanel>
		</apex:pageBlockSection>
		<apex:pageBlockSection id="productionNew" title="Create Production Number for Membership">
			<apex:outputPanel styleClass="pageSection" layout="block">
				<apex:outputLabel for="newProdNo" value="New Production No*:" title="" /><br />
				<apex:inputText value="{!newProdNo}" /><br />
				<apex:outputText style="font-style: italic; font-size: 10px;" value="*Enter a new Production Number to this Contact and associated Branch. This will also create a Production Membership" /><br />
			</apex:outputPanel>
		</apex:pageBlockSection>
	</apex:pageBlock>
</apex:form>

Here's my controller:

 

 

public with sharing class quickCreateProduction {
	
	private ApexPages.StandardController controller;
	
	public quickCreateProduction(ApexPages.StandardController controller) {
		
		this.controller = controller;
		
		productionNumbers = new List<Id>();
		selectedNumbers = new List<Id>();
		
	}
	
	Id id = ApexPages.currentPage().getParameters().get('id');
	
	List<SelectOption> productionOptions = new List<SelectOption>();
	List<SelectOption> selectedOptions = new List<SelectOption>();

	ApexPages.Standardsetcontroller accBranch = new ApexPages.Standardsetcontroller(Database.getQueryLocator([SELECT Id FROM Contact WHERE Id =: id AND Account.RecordTypeId = '01230000000Q9p4AAC']));

	public Integer i {

		get { return accBranch.getResultSize(); }
		set { this.i = i; }
		
	}
	
	ApexPages.Standardsetcontroller ap = new ApexPages.Standardsetcontroller(Database.getQueryLocator([SELECT Id FROM Production_No__c WHERE Branch__c IN (SELECT AccountId FROM Contact WHERE Id =: id) AND Id NOT IN (SELECT Production_No__c FROM Production_Member__c WHERE Contact__c =: id)]));
	
	public Integer j {

		get { return ap.getResultSize(); }
		set { this.j = j; }
		
	}
	
	public List<SelectOption> getProductionOptions() {
		
		List<SelectOption> options = new List<SelectOption>();
		
		for (Production_No__c productionNo : [SELECT Id, Name, Branch__c FROM Production_No__c WHERE Branch__c IN (SELECT AccountId FROM Contact WHERE Id =: id) AND Id NOT IN (SELECT Production_No__c FROM Production_Member__c WHERE Contact__c =: id)]) {
			
			options.add(new SelectOption(productionNo.Id, productionNo.Name));
			
		}

		return options;
		
	}
	
	public void setProductionOptions(List<SelectOption> productionOptions) {
		
		this.productionOptions = productionOptions;
		
	}

	public List<SelectOption> getSelectedOptions() {
		
		List<SelectOption> options = new List<SelectOption>();
		
		for (Production_Member__c productionNo : [SELECT Production_No__c, Production_No__r.Name FROM Production_Member__c WHERE Contact__c =: id]) {
			
			options.add(new SelectOption(productionNo.Production_No__c, productionNo.Production_No__r.Name));
			
		}
		
		return options;
		
	}

	public void setSelectedOptions(List<SelectOption> selectedOptions) {
		
		this.selectedOptions = selectedOptions;
		
	}
	public List<Id> productionNumbers {	get; set; }

	public List<Id> selectedNumbers { get; set; }

	public String newProdNo {
		
		get { return newProdNo; }
		set { this.newProdNo = value; } 
		
	}
	
	public PageReference save() {

		ApexPages.Message msg = new ApexPages.message(ApexPages.Severity.INFO, 'Available: ' + productionNumbers + ' Selected: ' + selectedNumbers);
		ApexPages.addMessage(msg);

		return ApexPages.currentPage();
		
	}

}