I'm using an <apex:selectCheckboxes> element in a VF page, with the options coming from this controller method:

public List<SelectOption> GetTemplateOptions()
    List<SelectOption> options = new List<SelectOption>();

    if(templates == null)
        templates = new Map<Id, Template__c>();

        for(Template__c template : [select Id, Name from Template__c where RecordType.DeveloperName = 'template'])
            /* THE_BORK */
            templates.Put(template.Id, template);

    for(Template__c template : templates.Values()) 
        /* THE_LINE */
        options.Add(new SelectOption(template.Id, template.Name));

    return options;

I'm collecting the results in an initialised list of strings and it's all fine and dandy. However, if I move the line marked THE_LINE and put it where it says THE_BORK, the system is throwing an internal server error when calling an action on the page.

I've been unable to reproduce in a developer org and obviously I've found a work around, but can anyone see what's wrong here because I can't work it out (maybe I've been looking at it for too long).

  • I've had the same problem when I was re-populating picklist options in different methods. Had to re-initialise the list of options, otherwise I was getting the internal server error on re-rendering the page. Found a workaround too but never found out what was causing the issue... Oct 1, 2013 at 4:53
  • Best guess: the JSF or JSF-like processing model expects the List<SelectOption> to be in the view state so use non-transient field syntax instead of a getter "public List<SelectOption> templateOptions { get { … }; private set; }".
    – Keith C
    Oct 1, 2013 at 9:37
  • From the look of the code it shouldn't matter, but the "I've been unable to reproduce in a developer org" statement makes me wonder if there are any differences in the data between the orgs? Oct 1, 2013 at 22:05
  • Do you have a default value set for the checkbox? Might make a difference.
    – crmprogdev
    Oct 2, 2013 at 13:47
  • Just defaulted to blank. My test in a DE wasn't entirely identical so going to recreate it exactly sometime to see what's going on.
    – Matt Lacey
    Oct 2, 2013 at 22:19

1 Answer 1


Assuming the issue hasn't resolved itself, you could always try:

public SelectOption[] getTemplateOptions() {
    SelectOption[] options = new SelectOption[0];
    if(templates == null) {
        templates = new Map<Id, Template__c>(
            [SELECT Id, Name FROM Template__c WHERE RecordType.DeveloperName = 'template']
    for(Template__c record: templates.values()) {
        options.add(new SelectOption(record.Id, record.Name));
    return options;

Often, simple changes in code structure can resolve problems. Othertimes, salesforce.com issues hot-fixes for errors like this. There's nothing wrong with the original code, outside some general optimizations as I've provided here.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .