• ThatGuy2013
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies

I'm trying to create a set of picklists. The first list displays a list of record names (duplicate names are not listed), and the second picklist is supposed to display all the records related to the record selected in the first list (duplicate names are not listed). However, I cannot get the second picklist to populate correctly. I've looked into the examples provided by Salesforce, and I cannot see what I'm doing wrong. Any help would be greatly appreciated, thanks!

 

VisualForce Page:

<apex:page controller="FieldUpdaterController">
<apex:form >
    <apex:pageBlock title="Field Update Module">
        <apex:pageBlockSection columns="1">
        {!selectedDDP}
            <apex:pageBlockSectionItem >
                <apex:outputLabel value="Invoice Statement"/>
                <apex:selectList value="{!selectedInvoice}" size="1">
                    <apex:selectOptions value="{!availableInvoices}" />
                    <apex:actionSupport event="onchange" rerender="itemPicklist" />
                </apex:selectList>              
            </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem >
                <apex:outputLabel value="Line Item" />
                    <apex:selectList id="itemPicklist" value="{!selectedItem}" size="1">
                        <apex:selectOptions value="{!availableItems}" />
                    </apex:selectList>
            </apex:pageBlockSectionItem>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:form>
</apex:page>

 

 

 

APEX:

public class FieldUpdaterController {

    public String selectedItem {get; set;}
    
    public string selectedInvoice {get; set;}
    
    public List<selectOption> getAvailableInvoices() {
    
        List<selectOption> optionalInvoices = new List<selectOption>();
        
        List<Invoice_Statement__c> allInvoices = [SELECT Name, Id FROM Invoice_Statement__c ORDER BY Name];
            
        string prevInvoice;
        
        for (Invoice_Statement__c i : allInvoices) {
            if(i.Name != prevInvoice) {
                optionalInvoices.add(new selectOption('',i.Name));
            }
            prevInvoice = i.Name;
        }
        
        if (optionalInvoices.size() == 0) {
        optionalInvoices.add(new selectOption('', 'No Invoices Available'));
        return optionalInvoices;
        }
        else{
        return optionalInvoices;
        }
        
    }
    
    public List<selectOption> getAvailableItems() {
        
        List<selectOption> availableItems = new list<selectOption>();
        
        string prevItem;              
 
        for(Line_Item__c li : [SELECT Name, Id FROM Line_Item__c WHERE Invoice_Statement__r.Name = :selectedInvoice]) {
            if(li.Name != prevItem) {
                availableFields.add(new selectOption('', li.Name));
            }
            prevItem = li.Name;
        }
               
        return availableItems;
    }
    
}

 

I'm trying to create a set of picklists. The first list displays a list of record names (duplicate names are not listed), and the second picklist is supposed to display all the records related to the record selected in the first list (duplicate names are not listed). However, I cannot get the second picklist to populate correctly. I've looked into the examples provided by Salesforce, and I cannot see what I'm doing wrong. Any help would be greatly appreciated, thanks!

 

VisualForce Page:

<apex:page controller="FieldUpdaterController">
<apex:form >
    <apex:pageBlock title="Field Update Module">
        <apex:pageBlockSection columns="1">
        {!selectedDDP}
            <apex:pageBlockSectionItem >
                <apex:outputLabel value="Invoice Statement"/>
                <apex:selectList value="{!selectedInvoice}" size="1">
                    <apex:selectOptions value="{!availableInvoices}" />
                    <apex:actionSupport event="onchange" rerender="itemPicklist" />
                </apex:selectList>              
            </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem >
                <apex:outputLabel value="Line Item" />
                    <apex:selectList id="itemPicklist" value="{!selectedItem}" size="1">
                        <apex:selectOptions value="{!availableItems}" />
                    </apex:selectList>
            </apex:pageBlockSectionItem>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:form>
</apex:page>

 

 

 

APEX:

public class FieldUpdaterController {

    public String selectedItem {get; set;}
    
    public string selectedInvoice {get; set;}
    
    public List<selectOption> getAvailableInvoices() {
    
        List<selectOption> optionalInvoices = new List<selectOption>();
        
        List<Invoice_Statement__c> allInvoices = [SELECT Name, Id FROM Invoice_Statement__c ORDER BY Name];
            
        string prevInvoice;
        
        for (Invoice_Statement__c i : allInvoices) {
            if(i.Name != prevInvoice) {
                optionalInvoices.add(new selectOption('',i.Name));
            }
            prevInvoice = i.Name;
        }
        
        if (optionalInvoices.size() == 0) {
        optionalInvoices.add(new selectOption('', 'No Invoices Available'));
        return optionalInvoices;
        }
        else{
        return optionalInvoices;
        }
        
    }
    
    public List<selectOption> getAvailableItems() {
        
        List<selectOption> availableItems = new list<selectOption>();
        
        string prevItem;              
 
        for(Line_Item__c li : [SELECT Name, Id FROM Line_Item__c WHERE Invoice_Statement__r.Name = :selectedInvoice]) {
            if(li.Name != prevItem) {
                availableFields.add(new selectOption('', li.Name));
            }
            prevItem = li.Name;
        }
               
        return availableItems;
    }
    
}