I am trying to pick up all of the text field (Description__c )value from an object (National__c) and display those text values as a picklist in a visual force page. However I am facing an error - Argument 2 cannot be null.

Could you please help. Below are the code piece. getTypeOptions() is called from the controller.

      <apex:selectList id="description" value="{!s.Description__c}"  size="1" required="true">
        <apex:selectOptions value="{!TypeOptions}"/>

Controller -

 public List<SelectOption> getTypeOptions(){
       List<SelectOption> options = new List<SelectOption>();
       options.add(new SelectOption('None','--None--'));

       for (National__c obj2 : [SELECT Id,Description__c FROM National__c]) {
            options.add(new SelectOption(obj2.Id, obj2.Description__c));

Just before you populate the options in loop , put a null pointer check like : if(obj2.Description__c != null) then add options.add(new SelectOption(obj2.Id, obj2.Description__c));

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.