I'd like to add 3 picklist fields to an Account object in the following manner:
- Parent multi-select Picklist field (let's call it ParentMultiSelectField__c)
- A dependent mutli-select Picklist field (let's call it ChildMultiSelectField__c) is dependent on the values in
ParentMultiSelectField__c field- And a third single picklist field (let's call it ChildSinglePiclistField__c) is also dependent on the values in
ParentMultiSelectField__c field
For the sake of clarity, when I say dependent I mean that the values in the child fields will be filtered depending on the value(s) selected in the parent multi-select picklist.
My question is in 2 parts:
- Is this setup possible using standard salesforce point and click?
- If not, how do I implement this using visualforce and apex? (High level design should suffice)
Best Answer
Safe Harbor: this is a really long answer...read at your own risk. Also, none of this sample code has been tested, this is just me stubbing it out in Notepad++.
This is not currently possible with standard Salesforce configuration, as multi-select picklists cannot be selected as the Controlling Field in a Field Dependency. So, you're definitely looking at a VisualForce solution; your approach here really depends on your requirements. Does it need to be easily configurable, or is it feasible to hardcode the dependencies in your controller?
If it's acceptable to hardcode the dependencies in your controller, then you'll probably want to set up maps of the dependencies to simplify your code (I use the word "simplify" loosely here)...
And then your VF page...
However, if this needs to be easily configurable, then you're looking at a custom object with a lookup relationship to itself. You can then query the dependencies and build the maps from them instead of hardcoding them. Just throwing some ideas out there, let's say this custom object uses a Name field for its value, a FieldDep__c field as a lookup to it's controlling value, and a WhichPicklist__c field to control which picklist it belongs to (for this I'll just say it's an integer with possible values of 1, 2, and 3).
You would then want to populate FieldDep__c records from the top down so that you can add a lookup to the controlling value for each record.
I hope I didn't go too overboard with this! If I get a chance sometime today I'll put this together in an org to see how valid my code works, but it sounded like you were just looking for a push in the right direction (although this answer may have been slightly more than that...)