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
Christopher PezzaChristopher Pezza 

Using Multiple <SelectOption> in Apex and SelectList SelectOptions

public with sharing class CustomerHealth {

Public String CSMFilter {get ; set;}
public Set<String> cmSet {get; set;}

public CustomerHealth() {
       cmSet = new Set<String>();
    for(Customer_Health__c ch : [SELECT Customer_Success_Manager__c FROM Customer_Health__c   WHERE Customer_Success_Manager__c <> ' ']){
             cmSet.add(ch.Customer_Success_Manager__c);
       }//END for
   }//END public

public List<SelectOption> getCSMItems() {
        List<SelectOption> csmoptions= new List<SelectOption>();
        for (String s : cmSet) {
            csmoptions.add(new SelectOption(s, s));
        }
        return csmoptions;
    }
}
I created this an now want to create two more selct list the same as this but i get an error "Argument 1 cannot be null"

What My code looks like with multiple select list:
Controller:
public with sharing class CustomerHealth {

public Set<String> cmSet {get; set;}
public Set<String> amset {get; set;}
public Set<String> seset {get; set;}

public CustomerHealth() {
       cmSet = new Set<String>();
    for(Customer_Health__c ch : [SELECT Customer_Success_Manager__c FROM Customer_Health__c   WHERE Customer_Success_Manager__c <> ' ']){
             cmSet.add(ch.Customer_Success_Manager__c);
       }//END for
       amset = new Set<String>();
    for(Customer_Health__c cha : [SELECT Account_Manager__c FROM Customer_Health__c]){
             amset.add(cha.Account_Manager__c);
            }

    seset = new Set<String>();
    for(Customer_Health__c chs : [SELECT Support_Engineer__c FROM Customer_Health__c]){
             seset.add(chs.Support_Engineer__c);
            }
   }//END public

public List<SelectOption> getCSMItems() {
        List<SelectOption> csmoptions= new List<SelectOption>();
        for (String s : cmSet) {
            csmoptions.add(new SelectOption(s, s));
        }
        return csmoptions;
    }
public List<SelectOption> getSEItems() {
        List<SelectOption> seoptions = new List<SelectOption>();
        seoptions.add(new SelectOption('No Filter', 'Support Engineer'));
        seoptions.add(new SelectOption(' ', 'No SE'));
        for (String a : seset) {
            seoptions.add(new SelectOption(a, a));
        }
        system.debug('***' + seoptions);
        return seoptions;
    }

    public List<SelectOption> getAMItems() {
        List<SelectOption> amoptions = new List<SelectOption>();
        amoptions.add(new SelectOption('No Filter', 'Account Manager'));
        for (String d : amset) {
            amoptions.add(new SelectOption(d, d));
        }
        system.debug('***' + amoptions);
        return amoptions;
    }
}

Visual Force Page:
<apex:selectList size="1" styleClass="btn btn-green btn-xs" value="{!CSMFilter}" onchange="RefreshTable1()">
     <apex:selectOptions value="{!CSMItems}"></apex:selectOptions>
</apex:selectList> 
<span class="divider"></span>
<apex:selectList size="1" styleClass="btn btn-green btn-xs" value="{!SEFilter}" onchange="RefreshTable1()">
     <apex:selectOptions value="{!SEItems}"></apex:selectOptions>
</apex:selectList>
<span class="divider"></span>
<apex:selectList size="1" styleClass="btn btn-green btn-xs" value="{!AMFilter}" onchange="RefreshTable1()">
    <apex:selectOptions value="{!AMItems}"></apex:selectOptions>
</apex:selectList>


Best Answer chosen by Christopher Pezza
Christopher PezzaChristopher Pezza
I got it i needed to add a WHERE clause to eliminate the blanks in the query Thank you though

All Answers

Gopal RathoreGopal Rathore
Hi Christopher Pezza,

This Error "Argument 1 cannot be null" is Founded Due To You Have No Records In List. Check One Of The Field Did You Used Is Empty ? If Empty Create Record And Try Again.

And Add This Strings In Your Code 
public String AMFilter   {get; set;}
public String SEFilter   {get; set;}
Regards 
Gopal Rathore
Christopher PezzaChristopher Pezza
Yea i already have those strings in my code and i know that they aren't empty
Christopher PezzaChristopher Pezza
I got it i needed to add a WHERE clause to eliminate the blanks in the query Thank you though
This was selected as the best answer
Gopal RathoreGopal Rathore
Hi Christopher Pezza,
This Code Is Working On My Side 
User-added image

If There Is Records In Fields.
And If Fields Are Empty It Will Give Error...

Regards 
Gopal Rathore
Gopal RathoreGopal Rathore
Hi Christopher Pezza,

You Have To Add WHERE Clause To Eliminate The Blanks In The Query.
Because If Empty Records Is Added To The Set It Will Show Error System.NullPointerException: Argument 1 cannot be null..
And If You Use WHERE Clause It Will  Eliminate The Blanks From The Query.
After That Your Error Will Solved.

Regards 
Gopal Rathore