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

Dynamic picklist connected to custom object
Hi
I'm trying to link a custom field from the Account object that will create a picklist based on data from a custom lookup object
It works but I'm having problems getting to selected the current record value and to save the current picklist value to the Account record
Thanks in advance for you help
apex:page standardController="Account" > <apex:form > <tr><td>Municapaly</td><td> <p>test {!account.Municipaly__c}</p> <c:Municapaly_Dynamic_Picklist defaultvalue="(!account.Municipaly__c"> </c:Municapaly_Dynamic_Picklist> </td> <tr> </apex:form></apex:page> <apex:component controller="clsMuniciplayDynamicPicklist" ><apex:attribute name="defaultvalue" description="Dynamic Picklist value" type="String" required="true"></apex:attribute> <apex:selectList value="{!defaultvalue}" size="1"><apex:selectOptions value="{!items}"></apex:selectOptions></apex:selectList></apex:component> public class clsMuniciplayDynamicPicklist{ private Account CurrentAccount; public string defaultvalue{get;set;} private List<SelectOption> items; public List<SelectOption> getItems() { List<SelectOption> items = new List<SelectOption>(); for (Lookup_Tables__c lt: [Select l.Type__c, l.Start_Date__c, l.Name, l.End_Date__c, l.Code__c From Lookup_Tables__c l]){ items.add(new SelectOption( lt.Code__c,lt.Name)); }
apex:page standardController="Account" > <apex:form > <tr><td>Municapaly</td><td> <p>test {!account.Municipaly__c}</p> <c:Municapaly_Dynamic_Picklist defaultvalue="(!account.Municipaly__c"> </c:Municapaly_Dynamic_Picklist> </td> <tr> </apex:form> </apex:page> <apex:component controller="clsMuniciplayDynamicPicklist" > <apex:attribute name="defaultvalue" description="Dynamic Picklist value" type="String" required="true"></apex:attribute> <apex:selectList value="{!defaultvalue}" size="1"> <apex:selectOptions value="{!items}"> </apex:selectOptions> </apex:selectList></apex:component> public class clsMuniciplayDynamicPicklist { private Account CurrentAccount; public string defaultvalue{get;set;} private List<SelectOption> items; public List<SelectOption> getItems() { List<SelectOption> items = new List<SelectOption>(); for (Lookup_Tables__c lt: [Select l.Type__c, l.Start_Date__c, l.Name, l.End_Date__c, l.Code__c From Lookup_Tables__c l]){ items.add(new SelectOption( lt.Code__c,lt.Name)); }
Your defaultvalue attribute in your controller isn't associated with any attribute value, as you aren't using assignTo. However, you do have a property called defaultvalue in the controller, which may well be confusing matters.
Hi Bob
Thanks for your tip regarding the attribute value.
One more question. How would I bind the selected picklist to the underlying object field?
Thanks
Stephen
I think by the time your field is in the component, it is disconnected from the account object. I seem to recall that the field will be immutable if you pass it as an attribute, so you either need it in a wrapper class or in the original sobject. You'd probably need to pass the account object into the component like so:
apex:page standardController="Account" > <apex:form > <tr><td>Municapaly</td><td> <p>test {!account.Municipaly__c}</p> <c:Municapaly_Dynamic_Picklist defaultvalue="(!account"> </c:Municapaly_Dynamic_Picklist> </td> <tr> </apex:form> </apex:page> <apex:component controller="clsMuniciplayDynamicPicklist" > <apex:attribute name="defaultvalue" description="Account containing Dynamic Picklist value" type="Account" required="true"></apex:attribute> <apex:selectList value="{!account.Municipaly__c}" size="1"> <apex:selectOptions value="{!items}"> </apex:selectOptions> </apex:selectList> </apex:component> public class clsMuniciplayDynamicPicklist { private List<SelectOption> items; public List<SelectOption> getItems() { List<SelectOption> items = new List<SelectOption>(); for (Lookup_Tables__c lt: [Select l.Type__c, l.Start_Date__c, l.Name, l.End_Date__c, l.Code__c From Lookup_Tables__c l]){ items.add(new SelectOption( lt.Code__c,lt.Name)); }
Thanks for the prompt feedback
I will test it now
Hi Bob
I'm getting errors when I try and compile the new controller
Unknown property 'clsMuniciplayDynamicPicklist.account' Create Apex property 'clsMuniciplayDynamicPicklist.account' Create Apex method 'clsMuniciplayDynamicPicklist.getAccount'
Typo on my part. Change the attribute name in the component to account.
e.g.
<apex:attribute name="account" description="Account containing Dynamic Picklist value" type="Account" required="true"></apex:attribute>
Hi Bob
I have implemented the code as you suggested but having problems with the display of the inline Visualforce component in the main Account page. Could you please advise me on how to set is up correctly
<apex:page standardController="Account" showHeader="false" > <apex:form > <apex:outputPanel > <p>test {!account.Municipaly__c}</p> <p><c:Municapaly_Dynamic_Picklist account="{account}"></c:Municapaly_Dynamic_Picklist></p> </apex:outputPanel> </apex:form> </apex:page>
<apex:component controller="clsMuniciplayDynamicPicklist" > <apex:attribute name="account" description="Account containing Dynamic Picklist value" type="Account" required="true"></apex:attribute> <apex:selectList value="{!account.Municipaly__c}" size="1"> <apex:selectOptions value="{!items}"> </apex:selectOptions> </apex:selectList> <apex:outputText >test</apex:outputText></apex:component>
public class clsMuniciplayDynamicPicklist { public List<SelectOption> getItems() { List<SelectOption> items = new List<SelectOption>(); for (Lookup_Tables__c lt: [Select l.Type__c, l.Start_Date__c, l.Name, l.End_Date__c, l.Code__c From Lookup_Tables__c l]){ items.add(new SelectOption( lt.Code__c,lt.Name)); } return items; } }
Thanks in advance
Stephen
It's displaying the whole Account page where the inline VF page is placed
What page are you trying to embed the VF page into?