2

This is a large controller, so it's possible this is a naming issue, but I'm not able to get selected values for a section of code and want to see if someone sees something obvious that I'm missing.

Here's the related visualforce:

    <apex:pageBlock id="pblogcall">     

        <Table width="100%" id="custmrclient"  align="center"  >
            <tr>
            <td><apex:outputLabel value="Select Client Name "/>
            <apex:selectList id="piklst" required="true" tabindex="0" size="1" label="Select Client Name " >
                <apex:selectOptions Value="{!ClientOptions}" >
                </apex:selectOptions>
            </apex:selectList></td>
            </tr>
        </Table>

    </apex:pageBlock>

I've marked the area of code in the controller below using *** where I'm not seeing expected values for selections (in public void processSelected()) to help make it easier it find where I'm trying to read the values. I've also omitted LOTS of presumably unrelated code. I'll update later if there might be variable names that could be causing issues reading the selected values.

Controller:

// initialization code...

constructor
{
//.....
//at end of constructor:
getClientOptions();
}

// lots of other methods....

public list<Account> getClientOptnsLst()
{
    ClientOptnsLst = new list<Account>();
    ClientOptnsLst = [SELECT Id, Name FROM Account WHERE RecordType.DeveloperName = 'Client' AND Status__c = 'Open' order by Name ];        
    return ClientOptnsLst;

}

public map<string,string> getClientOptionsMap()
{
    ClientOptionsMap = new map<string,string>();
    ClientOptnsLst = getClientOptnsLst();
    if ( ClientOptnsLst != null && ClientOptnsLst.size() > 0 )
    {   
        for(Account a:ClientOptnsLst)
        {
            ClientOptionsMap.put(a.Id, a.Name);
            system.debug('acctId = '+ a.Id + ' acct name = '+ a.Name);

        }
        return ClientOptionsMap;
    }
    else
    {
        return null;
    }

}


public list<SelectOption> getClientOptions() 
{

    System.debug('---> start getClientOptions() Picklist');        

    ClientOptionsMap = getClientOptionsMap();

    ClientOptions = new list<selectOption>();

    ClientOptions.add( new SelectOption( ' Select Client ', ' Select Client ', true )); // ==> option disabled

    if (!ClientOptionsMap.isEmpty() && ClientOptionsMap.keyset().size()>0 )
    for(string aId:ClientOptionsMap.keyset())
    {

        ClientOptions.add(new SelectOption(aid, ClientOptionsMap.get(aId)));
        system.debug('acctId = '+ aId + ' acct name = '+ ClientOptionsMap.get(aId));

    }

    // If a client is in context, need to set it as 'selected' in picklist
    if(null!=clientId) selected 
    { 
        setSelectedClient(string.valueOf(clientId));
    }

    return ClientOptions;

}


public String getSelectedClient() {
    return selectedClient;
}

public void setSelectedClient(String selectedClient) {
    this.selectedClient = selectedClient;

} 

public void processSelected() {

    string RT = string.valueOf(fsentries.StoreVisitRT__c);

    try {
        // Create a task for every selected thing
        List<Task> ntsks = new List<Task>();

        //**** This IS NOT WORKING ****
        for (SelectOption selOption : ClientOptions)
        {   
            system.debug('For loop selOption.getValue=  '+ selOption.getValue() +' selectedClient= '+selectedClient);

            //**** selectedClient ALWAYS returning null :(

            if (selOption.getValue() == selectedClient)
            {                   
                clientId = string.valueOf(selectedClient);
                currentClientName = selOption.getLabel();
            }
        }

        if(null != clientId)
        {
            system.debug('clientId = ' +clientId);
            system.debug('Client__c = '+currentClientName );    
        }else{
            system.debug('clientID == null');
            system.debug('selectedClient= '+selectedClient);
        }

        system.debug('----> Entering Selection For Loop to Create Tasks');

        for (ssOption m:MS) {
            if (m.selected) {
                Task t = new Task(Subject = 'xxx', Description = m.descr, Customer__c = custmrUPrntName, Type = m.option, OwnerId = usrId, WhatID = customerId, ActivityDate = system.today() );
                if(null != clientId)
                {
                    t.Client1__c = clientId;
                    t.Client__c = currentClientName;                        
                }

                ntsks.add(t);
            }
        }

        if(ntsks.isEmpty() == false)
        {
            insert ntsks;

        }

    } catch (Exception ex) {

        // show the problem
        ApexPages.addMessages(ex);
        system.debug('Apex Exception');
    }

}
3

You need a value binding:

<apex:selectList value="{!selectedClient}">
    <apex:selectOptions value="{!clientOptions}" />
</apex:selectList>
  • Thank you sir! Nothing like chasing your tail in circles all day looking for the obvious! (blushes) – crmprogdev Feb 12 '16 at 21:08
  • Glad I could help! Wasn't sure if that would be it, haha. – Adrian Larson Feb 12 '16 at 21:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.