In my controller I have a static list of select options:
public List<SelectOption> getVesselTypeList() {
List<SelectOption> options = new List<Selectoption>();
options.add(new selectOption('OTH', 'SOLAS Vessel'));
options.add(new selectOption('NONM', 'Non-SOLAS Vessel'));
options.add(new selectOption('NOT', 'Not a Vessel'));
return options;
}
Selected options value should be stored in custom field VesselType__c. Field is of type text with length of 8 characters which is enough for all values:
<apex:selectList value="{!ZInstallation__c.VesselType__c}" size="1">
<apex:selectOptions value="{!VesselTypeList}" />
</apex:selectList>
Produced HTML:
<select name="j_id0:j_id2:j_id4:j_id11:j_id57:j_id59" size="1">
<option value="OTH">SOLAS Vessel</option>
<option value="NONM">Non-SOLAS Vessel</option>
<option value="NOT">Not a Vessel</option>
</select>
On update/insert I get this error message:
Update failed. First exception on row 0 with id a8qO0000000CbIEIA0; first error: STRING_TOO_LONG, Type of ship:: data value too large: SOLAS Vessel (max length=8): [VesselType__c] Error is in expression '{!submit}' in component in page z_installation: Class.ZInstallationController.submit: line 414, column 1
It seems as if Salesforce stores the options text in field VesselType__c and not its value. How can I save the options value in my text field?