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
Ken KoellnerKen Koellner 

limits on values in selectOption "Value is not valid"

I got "Value is not valide" error message when a particularly values was selected. I used the name text for value and name when creating the selectOption in Apex and they were both "Test that a My APPT CPT can have more than 75 characters."

That's an exact quote with the "." being in the text.

I made a coding change and left the label as is but changed the value to an artifical key.  It works fine now.

I'm thinking there's some limit on who long or what can be in the value member of a selectOption.  The Apex and VF manuals do not mention any restrictions in the documentation for the selectOption class.

I'm thinking maybe either the length or the "." broke it.

Anyone know if there are some limitation to what can be in the value member?  If so, are they documented somewhere else?
Ashish_SFDCAshish_SFDC

Hi Ken, 


String size: Strings have no limit on the number of characters they can include. Instead, the heap size limit is used to ensure that your Apex programs don't grow too large.

http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_primitives.htm

With the examples of string it does not say there are any invalid characters or special characters cannot be used. 


Regards,

Ashish

 

Ken KoellnerKen Koellner
I seriously doubt it has anything to do with heap size.  The string is < 100 characters.  I think it has something to do with how VF select lists work.  Either it doesn't like a character in the value member of the select option or it doesn't like the size.
Ashish_SFDCAshish_SFDC
Hi Ken, 


The separator string used in the split method is a regular expression and "." is a special character in regular expressions.

The regular expression for a literal "." is "\."

However "\" is also used to escape characters when expressing Strings in Apex, and so this character too needs escaping:

String[] cd = createDate.split('\\.');
The documentation provides an interesting example, if you need to use "\" as the separator:

List<String> parts = filename.split('\\\\');

http://salesforce.stackexchange.com/questions/8985/bug-in-string-split

Also see the below post,

https://developer.salesforce.com/forums?id=906F00000008yn4IAA


Regards,
Ashish