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

Dynamic picklist connected to custom object

I was wondering if somebody could help me. I have create a dynamic picklist controller that collects it select list from a custom lookup table

I have a custom field called Municapaly on the Account object and I would like to link and update this field from this new controller 


<apex:page standardController="Account" >  <apex:form >  <tr><td>Municapaly</td><td>   <c:Municapaly_Dynamic_Picklist myvalue="1"> </c:Municapaly_Dynamic_Picklist>   </td>  <tr>

  </apex:form></apex:page>  <apex:page standardController="Account" >

  <apex:form >  <tr><td>Municapaly</td><td>   <c:Municapaly_Dynamic_Picklist myvalue="1"> </c:Municapaly_Dynamic_Picklist>   </td>  <tr>

  </apex:form></apex:page>  public class clsMuniciplayDynamicPicklist{    private List<SelectOption> items;       public List<SelectOption> getItems() {         List<SelectOption> items = new List<SelectOption>();         //default value         items.add(new SelectOption('','--Select Record Type --'));        

        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;     }




Can you paste your code in via the insert code button (clipboard symbol with a C on it).


Otherwise the formatting means we can't understand it without reformatting ourselves. 


Thanks for showing me how to insert code. It's a big help.


Below is the code showing the page, controller and class code

The problems that I have at the moment are as follows

1) How do I link the underlying Municilpaly record to display as the select Municilpaly?

2) If the user selects a different Municilpaly how does one save the value to the Account object?

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)); } return items; } }


Gino BassoGino Basso
I would suggest passing the account into your custom component and binding to the custom field directly. That way any changes the user makes will automatically be reflected in the account record. You can then trim down your controller class (the one for your custom component) to just getItems.

Hi Gino


Could you please provide me a code snippnet on how I would bind the field directly to the custom field once the account has been passed from the custom component.








Did you manage to find the code snippet that dinamically binds the custom component to the custom field in the "page object"?


You could post the code, I would greatly appreciate it.


Thanks in advance,


Luís Silva 

Prafulla PatilPrafulla Patil