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
scottnelsonsmithscottnelsonsmith 

apex:selectList; error "An error occurred when processing your submitted information."

I've reduced my code down to the minimum to get this result.  What I'm trying to do is run a process against a subset of contacts for an account.  Here's the VisualSource page and the controller code:

 

 

// The visualsource page:
<apex:page standardController="Account" tabStyle="Account" sidebar="false" extensions="AccountExtensions">
<apex:form >
<apex:pageBlock title="Assign Sector Access Logs">
<apex:messages />
<apex:pageBlockButtons >
<apex:commandButton action="{!save}" value="Mass Assign" id="massAssign" />
<apex:commandButton action="{!cancel}" value="Cancel" id="massCancel" />
</apex:pageBlockButtons>
<apex:pageBlockSection columns="1">
<apex:pageBlockSectionItem >
<apex:outputLabel value="Contacts to mass-assign SAL's to:" for="contacts_list"/>
<apex:selectList value="{!selContacts}" size="10" multiselect="true" id="contacts_list" required="true">
<apex:selectOptions value="{!contactsForAccount}" />
</apex:selectList>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
// The controller
public with sharing class AccountExtensions
{
private final Account account;
private List<Contact> contacts;
private List<SelectOption> selContacts;


public AccountExtensions(Apexpages.StandardController asControl)
{
this.account = (Account) asControl.getRecord();
this.contacts = [select id, name, AccountId from Contact where AccountId = : account.id];
this.selContacts = new List<SelectOption>();
}

public PageReference save()
{
System.debug(' **** Begin save **** ');
return null;
}

public List<SelectOption> getSelContacts()
{
return this.selContacts;
}

public void setSelContacts( List<SelectOption> selected)
{
this.selContacts = selected;
}

public List<SelectOption> getContactsForAccount()
{
List<SelectOption> options = new List<SelectOption>();
for( Contact c : contacts)
{
options.add(new SelectOption(c.id, c.name));
}
return options;
}

public void setContactsForAccount(List<SelectOption> options)
{

}
}

 

 

When I click the "Mass Assign" button, I get the following "validation" message:

 

Error Screen

Best Answer chosen by Admin (Salesforce Developers) 
scottnelsonsmithscottnelsonsmith

Ah, found the problem.

 

selContacts needs to be String[], not List<SelectOption>.

 

Better diagnostic message would definitely help.

 

New listing for those who are interested:

 

 

public with sharing class AccountExtensions
{
    private final Account account;
    private List<Contact> contacts;
    private List<String> selectContacts;

    
    public AccountExtensions(Apexpages.StandardController asControl)
    {
        this.account = (Account) asControl.getRecord();
        this.contacts = [select id, name, AccountId from Contact where AccountId = : account.id];
        this.selectContacts = new List<String>();
    }

   public PageReference save()
    {
        System.debug(' **** Begin save **** ');
        return null;
    }
    
    public List<String> selContacts
    {
    get
    {
        return this.selectContacts;
    }
    
    set
    {
        System.debug('*** Called? ***');
        this.selectContacts = value;
    }
    }

    public List<SelectOption> getContactsForAccount()
    {   
        List<SelectOption> options = new List<SelectOption>();
        for( Contact c : contacts)
        {
          options.add(new SelectOption(c.id, c.name));
        }
        return options;
    }
    
    public void setContactsForAccount(List<SelectOption> options)
    {

    }   
}