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
adreameradreamer 

Inconsisten SelectOption ?

Hi All,

 

The SelectOption connstructor is setting the value and label the other way around ?

 

Here is the output of an execute anonymous:

 

Anonymous execution was successful.

20.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;VALIDATION,INFO;WORKFLOW,INFO
Execute Anonymous: List<SelectOption> etOpts = new List<SelectOption>();
Execute Anonymous: etOpts.add(new SelectOption('value','label'));
Execute Anonymous: System.debug('options --> '+etOpts);
16:35:46.053 (53364000)|EXECUTION_STARTED
16:35:46.053 (53402000)|CODE_UNIT_STARTED|[EXTERNAL]|execute_anonymous_apex
16:35:46.054 (54365000)|USER_DEBUG|[3]|DEBUG|options --> (System.SelectOption[value="label", label="value", disabled="false"])
16:35:46.941 (54452000)|CUMULATIVE_LIMIT_USAGE

 

The red line is where I construct the SelectOption following the manual : SelectOption option = new SelectOption(value, label, isDisabled);

 

However when I look at the list with the debug statement, the blue part,  they are the other way around.

 

To make things worse when I look at the actual visualforce page in action, the labels correspond to the labels I expect and the values correspond to the values I expect. I got to the point to look at the execute anonymous because in a test method I am getting the wrong behaviour -i.e. the value and label are the other way around so the assertions fail. But they fail because the option value and label are the other way around.

 

Any ideas ?

 

Thanks,

Fernando

 

Best Answer chosen by Admin (Salesforce Developers) 
aballardaballard

How are you referencing it in your testMethod that causes the failure?

 

There is a known bug with selectOption (fixed in next release) displaying the wrong values in a debug statement, but it should give the right values if you access the individual values via option.getValue() and option.getLabel(). 

 

All Answers

aballardaballard

How are you referencing it in your testMethod that causes the failure?

 

There is a known bug with selectOption (fixed in next release) displaying the wrong values in a debug statement, but it should give the right values if you access the individual values via option.getValue() and option.getLabel(). 

 

This was selected as the best answer
adreameradreamer

Thank you very much for the information on the behaviour of SelectOption in debug statements.

 

The issue was somewhere else, it is fine now, but it is good to know how to interpret the debug output with a SelectOption until this is fixed.

 

Regards,

Fernando