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
rahmedrahmed 

autofill dependent picklist using VF and apex

I used the example on http://wiki.developerforce.com/index.php/Extended_Functionality_of_Visualforce_-_Part_2 to make a VF page that has 2 picklists. one is dependent on the other. I bascally need to render the second picklist (trader) when i make a selection on the first one (acctName). My problem is that the acctNname picklist populates, but when i make a selection the other picklist (trader) does NOT populate aoccrdingly - it stays empty.

 

<apex:page standardController="Case" extensions="CaseExtension" standardStylesheets="true"> 

<apex:sectionHeader title="Request Information" subtitle="{!case.id}"></apex:sectionHeader>

<apex:form >

<apex:pageBlock title="Request Information" mode="edit">

<apex:outputLabel value="Account Name" for="acctName"></apex:outputLabel>

<apex:selectList id="acctName" value="{!acctName}" size="1">

<apex:actionSupport event="onchange" rerender="trader"/>

<apex:selectOptions value="{!Accts}"></apex:selectOptions>

</apex:selectList> 

<apex:pageBlockSectionItem >

<apex:outputLabel value="Trader ID" for="trader"></apex:outputLabel>

<apex:selectList id="trader" value="{!trader}" size="1" title="Trader ID" >

<apex:selectOptions value="{!Tids}"></apex:selectOptions>

</apex:selectList>

  

 

</apex:pageBlock> </apex:form>

</apex:page>

 

apex class:
-----------

public class CaseExtension {

private final Case u;

public CaseExtension(ApexPages.StandardController stdController) { this.u = (Case)stdController.getRecord(); }

String acctName;

String trader;

public String getacctName() { return acctName; }

public void setacctName(String s) {  this.acctname = s; }

public String gettrader() {  return trader; }

public void settrader(String s) {  this.trader = s; }

 

public List<selectOption> getAccts() {

List<selectOption> optionList = new List<selectOption>();

optionList.add(new selectOption('', '- None -'));  

for (Account a : [SELECT name FROM Account order by Name]) {  

optionList.add(new selectOption(a.Id, a.Name));  

}

return optionList;  

}

public List<selectOption> getTids() {

List<selectOption> optionList = new List<selectOption>();   

optionList.add(new selectOption('', '- None -')); 

for (Firm_Trader_ID__c r : [SELECT name FROM Firm_Trader_ID__c r WHERE r.Account__r.Name = :acctName]) { 

optionList.add(new selectOption(r.Id, r.Name));  

}

return optionList;

}

}

------

What am i missign here? help on this matter will be appreciated.

Best Answer chosen by Admin (Salesforce Developers) 
Mikko4Mikko4

Hi,

 

I think the reason is in the query where statement. Try removing "r." (WHERE r.Account__r.Name = :acctName])