1

I have a controller as below

<apex:page controller="SampleController">
   <apex:form >
      <apex:pageblock >
         <apex:pageBlockSection >
            <apex:outputLabel value="Country" />
            <apex:selectList multiselect="false" value="{!selectOption}" size="1">
               <apex:selectOptions value="{!options}"></apex:selectOptions>
            </apex:selectList>
         </apex:pageBlockSection>
      </apex:pageblock>
   </apex:form>
</apex:page>

And Apex class as below.

public without sharing class SampleController {

    public SampleController() {}

    public String selectOption { get; set;}

    public SelectOption[] getOptions() {
        SelectOption[] options = new SelectOption[] {};
        options.add(new SelectOption(' ', '---Select---'));
        for (AggregateResult ar: [Select billingcountry n 
                                    from account group by billingcountry]) 
        {
            String n = (String) ar.get('n');
            options.add(new SelectOption(n, n));
        }
        return options;
    }
}

When I see the preview, I have the below message.

System.NullPointerException: Argument 1 cannot be null Class.SampleController.getOptions: line 17, column 1

I checked the query in queryeditor, I have the data for it. Pls help.

0

1 Answer 1

0

Change your query to filter out null values like this:

[Select billingcountry n from account where BillingCountry != Null group by billingcountry]
1
  • As BillingCountry is not a number or Id field, would this be better?: [Select billingcountry n from account where (billingcountry != null OR billingcountry != '') group by billingcountry] Commented May 3, 2016 at 10:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .