+ Start a Discussion
BhmBhm 

getting the picklist values from the contact object

Hi,

any one can plz help me,why i am gettind System.NullPointerException: Argument 2 cannot be null

 

 

public class countryExtension
{
public Contact c;

public countryExtension(ApexPages.StandardController stdController)
{
this.c = (Contact)stdController.getRecord();
}
public List<selectOption> getaccts()
{
List<selectOption> options = new List<selectOption>();
options.add(new selectOption('', ''));
for (Contact c : [SELECT id, Level__c FROM Contact Limit 1])
{
System.debug(c);
options.add(new selectOption(c.id, c.Level__c));
}
return options;
}
}

..............

<apex:page standardController="Contact" extensions="countryExtension" standardStylesheets="true">
<apex:form >
<apex:pageBlock title="Contact Edit" mode="edit">

<apex:pageBlockSection title="General Information" columns="1">
<apex:inputField value="{!Contact.FirstName}"></apex:inputField>
<apex:inputField value="{!Contact.LastName}"></apex:inputField>
<apex:inputField value="{!Contact.Department}"></apex:inputField>
<apex:inputField value="{!Contact.Phone}"></apex:inputField>
<apex:inputField value="{!Contact.Email}"></apex:inputField>
</apex:pageBlockSection>
<apex:pageBlockSection columns="1" showHeader="false">
<apex:pageBlockSectionItem >
<apex:outputLabel value="Country Name" for="accts"></apex:outputLabel>
<apex:selectList id="accts" value="{!Contact.Level__c}" size="1" title="Contact">
<apex:selectOptions value="{!accts}"></apex:selectOptions>
</apex:selectList>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

Prafull G.Prafull G.

Please make sure Level__c is not blank. When Level__c is NULL/BLANK it will cause the reported issue.

 

You can modify your query to get rid of this issue as

 

for (Contact c : [SELECT id, Level__c FROM Contact WHERE Level__c <> NULL Limit 1])

 

Hope it helps.