I am currently working on a wizard to allow our users to create Opportunities easier. I have the following field dependencies set up on a related object:
- 'Type' picklist (Controlling Field) to 'Sub Type' picklist (Dependent Field)
- 'Sub Type' picklist (Controlling Field) to 'Options' multi select picklist
- 'Type' picklist (Controlling Field as in 1) to 'Options 2' multi select picklist
Numbers 1. and 2. above is part of a multi layered dependency, while 3. is a single dependency.
When I add these fields to the wizard the dependencies work but if I click Next/Previous in my wizard then go back to the page with these fields on I lose my data from the multi select picklist 'Options'. The strange thing is that data for 'Options 2' multi select picklist is fine.
Essentially, it seems this only happens when I have a two-level dependency, where the dependent field is a multi select picklist. I've tried to replace the multi select picklist with a standard picklist and there is no loss of data. I also think the data is still set in the field (when looking from the controller) but just doesn't show up on the visualforce page.
Is this a known issue and are there any workarounds here?
UPDATE (22/04/2013):
Posted code below - this is a page I mocked up so I could easily attempt to fix the issue:
WizardPage1:
<apex:page StandardController="Custom_Object__c" extensions="WizardPageController">
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton action="{!page1}" value="Previous" />
</apex:pageBlockButtons>
<apex:pageBlockSection >
<apex:inputField value="{!Custom_Object__c.Type__c}" />
<apex:inputField value="{!Custom_Object__c.Options_2__c}" />
<apex:inputField value="{!Custom_Object__c.Sub_Type__c}" />
<apex:inputField value="{!Custom_Object__c.Options__c}" />
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
WizardPage2:
<apex:page StandardController="Custom_Object__c" extensions="WizardPageController">
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton action="{!page1}" value="Previous" />
</apex:pageBlockButtons>
<apex:pageBlockSection >
<apex:outputField value="{!Custom_Object__c.Type__c}" />
<apex:outputField value="{!Custom_Object__c.Options_2__c}" />
<apex:outputField value="{!Custom_Object__c.Sub_Type__c}" />
<apex:outputField value="{!Custom_Object__c.Options__c}" />
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
WizardPageController:
public with sharing class WizardPageController {
private Custom_Object__c record;
public WizardPageController(ApexPages.StandardController controller) {
this.record = (Custom_Object__c) controller.getRecord();
}
public PageReference page2() {
return Page.WizardPage2;
}
public PageReference page1() {
return Page.WizardPage1;
}
}
I've also realised that this issue also affects the 'Options 2' multi picklist as well. I didn't realise this before as I had forgotten to set the field dependency up for this field.
The issue seems to be the way Salesforce have handled the dependencies/multi select picklists in visualforce. The page generation appears to do the following:
- Load values into all fields on page
- Load dependencies for fields
- Load multi select picklist options based on dependencies
As the loading of multi select picklist options are done last, I think when the values are loaded onto the fields there are no options and therefore will not set the options as 'selected'.