You need to sign in to do that
Don't have an account?

How to bind a dynamic picklist value to an actual field
In visualforce, if I've got a couple of dynamic picklists, is it possible to bind the selected value to a real standard or custom field?
In other words let's say I've got a visualforce page that overrides the Lead edit page. This vf page has a couple dynamic picklists on it. On selecting values in those dynamic picklists, the user would click save, and the selected values would be mapped to actual fields on the Lead object. Not sure how to do this.
Here's a simple vf page that could override the lead edit button, along with it's custom controller. It seems to work, except for actually saving the dynamic picklist selections to the database.
Any help is appreciated
In other words let's say I've got a visualforce page that overrides the Lead edit page. This vf page has a couple dynamic picklists on it. On selecting values in those dynamic picklists, the user would click save, and the selected values would be mapped to actual fields on the Lead object. Not sure how to do this.
Here's a simple vf page that could override the lead edit button, along with it's custom controller. It seems to work, except for actually saving the dynamic picklist selections to the database.
Any help is appreciated
vf page: <apex:page standardController="Lead" extensions="DependentObjects" id="UseCaseDisplay" label="FeatureCategoryReport"> <apex:form > <apex:pageBlock title="New Lead" mode="edit"> <apex:pageBlockButtons > <apex:commandButton action="{!save}" value="Save"/> <apex:commandButton action="{!cancel}" value="Cancel"/> </apex:pageBlockButtons> <apex:pageBlockSection id="section1" title="Lead Information" columns="2" collapsible="true" ondblclick="toggleInputFieldsSales();"> <apex:inputField value="{!lead.LastName}"/> <apex:inputField value="{!lead.Email}"/> <apex:inputField value="{!lead.Company}"/> <apex:inputField value="{!lead.LeadSource}"/> <apex:inputField value="{!lead.Lead_Source_Detail__c}" /> </apex:pageBlockSection> <apex:pageblocksection > <table border="0" width="923px;"> <tr> <td align = "right"> <apex:outputLabel style="font-weight:bold;font-size:11px;" value="Lead Source" for="category"/> </td> <td> <apex:selectList style="align:right;" value="{!category}" size="1" id="category"> <apex:selectOptions value="{!categories}"/> <apex:actionSupport event="onchange" rerender="features"/> </apex:selectList> </td> </tr> <tr> <td align = "right"> <apex:outputLabel style="font-weight:bold;font-size:11px;" value="Lead Source Detail" for="features"/> </td> <td> <apex:selectList value="{!feature}" size="1" id="features" disabled="{!ISNULL(category)}"> <apex:selectOptions value="{!features}"/> </apex:selectList> </td> </tr> </table> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page> controller: public class DependentObjects { private final Lead acct; // The extension constructor initializes the private member // variable acct by using the getRecord method from the standard // controller. public DependentObjects(ApexPages.StandardController stdController) { this.acct = (Lead)stdController.getRecord(); } public String selectedAccName {get; set;} public DependentObjects() { selectedAccName = ''; } return page; } /* String value for the category */ String category; /* String value for the feature */ String feature; /* Getter for the category value */ public String getCategory() { return this.category; } /* Setter for the category value */ public void setCategory(String s) { this.category = s; } /* Getter for the feature value */ public String getFeature() { return this.feature; } /* Setter for the feature value */ public void setFeature(String s) { this.feature = s; } /* Getter which dynamically generates the categories from the Feature_Category__c object. */ public List<SelectOption> getCategories() { //List<SelectOption> optionList = new List<SelectOption>(); /* Add a null option to force the user to make a selection. */ // options.add(new SelectOption('','- None -')); /* Loop through the Lead records creating a selectOption for each result with the record ID as the value and the name as the label displayed in the selectList */ Set<String> uniqueCustomObjectSet = new Set<String>(); List<SelectOption> options = new List<SelectOption>(); options.add(new SelectOption('','- None -')); for(LeadSourceHidden__c sl:[Select LeadSourceHidden__c,Name From LeadSourceHidden__c WHERE LeadSourceHidden__c != null ORDER BY LeadSourceHidden__c DESC ]) { uniqueCustomObjectSet.add(sl.LeadSourceHidden__c); } List<String> uniqueCustomObjectList = new List<String>(uniqueCustomObjectSet); for(integer i=0; i<uniqueCustomObjectList.size(); i++){ options.add(new SelectOption(uniqueCustomObjectList[i],uniqueCustomObjectList[i])); } //options.add(new SelectOption('test','test')); return options; } /* Getter which generates the options for the features selectList based on the current value of the selected category. If there is no value selected then only the null option should be returned. */ public List<SelectOption> getFeatures() { List<SelectOption> optionList = new List<SelectOption>(); /* Add a null option to force the user to make a selection. */ optionList.add(new SelectOption('', '- None -')); /* If a category has been selected then query for the related values */ if(category != NULL) { /* Loop over the related campaign records for the given lead source creating a selectOption with the value being the feature record ID and the label is the name of the lead source. */ for (Campaign f : [select Name,Type from Campaign f where f.Type =: category LIMIT 40000 ]){ optionList.add(new SelectOption(f.Id,f.Name)); } } return optionList; } }
But still, lookup values won't be populated unless you specifically query them out.
In your constructor where there is currently the line that reads
theLead = (Lead)stdController.getRecord();
You'll have to replace it with something like this;
All Answers
http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_selectList.htm
Just a couple of things;
I've had best results using an apex:actionRegion doing this.
Also - I had some problems compiling the code you posted, so I gave it a whirl to try and get it going -- and in the process, I did a lot of rearranging.
Oh, and I took a couple fields out, but I think you shouldn't have any problems putting them back.
Hope this helps;
VF Page;
Page Controller extension;
There's more than one way to do it, but the actionFunction is synching the value of the onChange value with the controller, and the controller rebuilds the features list. I changed around the look and feel too but you can mess with that too.
Got it -
You have to override the save methos in your class.
VF Page;
Controller;
In the working code below, the field called Account is the lookup, and the fields "Title Function" and "PingOne Subscriber Status" are picklsit type fields on lead. Any idea if it's possible to render those as lookups/picklist type fields, and allow the user to save their selection to that underlying field? Thanks a lot for your help:
But still, lookup values won't be populated unless you specifically query them out.
In your constructor where there is currently the line that reads
theLead = (Lead)stdController.getRecord();
You'll have to replace it with something like this;
My only remaining question at this point is...what is your opinion on writing test classes on the vf page and controller above? Do you think it is necessary in this situation to write a test class? I'm not sure, but I guess maybe it is, because I am technically setting a couple of field values when a record is inserted or updated.