Skip to main content
Tweeted twitter.com/#!/StackSalesforce/status/419646685900718080
deleted 440 characters in body
Source Link
Robin
  • 555
  • 4
  • 18
  • 34

When I try to save, the page gets saved but returns a Visualforce error: System.NullPointerException: Argument 1 cannot be null

Class.UserStatsController.getValues: line 20, column 1

Following is the code for visual pageVF:

<apex:page Controller="UserStatsController">

<apex:sectionHeader title="Goal Revision Dashboard" subtitle="District View"/> <apex:pageBlock title="User Stats">

<apex:form > <apex:actionRegion > <apex:actionFunction name="RefreshRgn" rerender="dist, District" > <apex:param name="firstParam" assignTo="{!Regn}" value="" /> </apex:actionFunction>

<apex:sectionHeader title="Goal Revision Dashboard" subtitle="District View"/>
<apex:pageBlock title="User Stats">
<apex:form >
 <apex:outputLabel value="Region" />
        <apex:selectList value="{!Regnregn}" size="1" id="Region" required="true" onchange="RefreshRgn(this.value)">required="true">
            <apex:selectOptions value="{!Valuesr}" />
        </apex<apex:SelectList>actionSupport event="onchange" reRender="districtSelect"/>
    </apex:actionRegion>SelectList>
   <apex:outputPanel id="districtSelect">
    <apex:outputLabel value="District" />
    <apex:selectList value="{!dist}" size="1" id="dist" required="true">
        <apex:selectOptions value="{!valuesValues}">
        <apex:actionsupport event="onchange" rerender="SalesId""/>
 
        </apex:selectOptions>
    selectList>
    </apex:selectList>

</apex:form>outputPanel>
</apex:pageBlock>page>

</apex:page>

And following is the controller

public with sharing class UserStatsController {

    public string Regnregn {get; set;}
    public string dist {get; set;}    

    public list <SelectOption> getValuesr()
    {
    list <selectoption> lsreg = new List<selectoption> ();
    lsreg.add(new SelectOption('', '--None--'));
    for (User_Stats__C RegnRgn : [SELECT Region__c FROM User_Stats__C where Region__c != null and Region__c != 0 and District__c != null and District__c != '0' limit 10])
    {
        lsreg.add(new selectoption(string.valueOf(RegnRgn.Region__c), string.valueOf(RegnRgn.Region__c)));
    }
    return lsreg;
    }
    
  public list <SelectOption> getValues()
{
    list <selectoption> ls public= listnew <SelectOption>List<selectoption> getValues();
    {
ls.add(new SelectOption('', '--None--'));
  list <selectoption> lsInteger regnInt = new(regn!=null) List<selectoption>? Integer.valueOf(regn); : -1;
    for (User_Stats__C dist : [SELECT District__c FROM User_Stats__C where Region__c =: integer.valueof(apexpages.currentpage().getparameters().get('Regn'))regnInt and District__c != '' and Region__c != null and Region__c != 0 limit 10])
    {
        ls.add(new selectoption(dist.District__c, dist.District__c));
    }
    return ls;
    } 
}

Thanks in advance!.

When I try to save, the page gets saved but returns a Visualforce error: System.NullPointerException: Argument 1 cannot be null

Class.UserStatsController.getValues: line 20, column 1

Following is the code for visual page:

<apex:page Controller="UserStatsController">

<apex:sectionHeader title="Goal Revision Dashboard" subtitle="District View"/> <apex:pageBlock title="User Stats">

<apex:form > <apex:actionRegion > <apex:actionFunction name="RefreshRgn" rerender="dist, District" > <apex:param name="firstParam" assignTo="{!Regn}" value="" /> </apex:actionFunction>

        <apex:outputLabel value="Region" />
        <apex:selectList value="{!Regn}" size="1" id="Region" required="true" onchange="RefreshRgn(this.value)">
            <apex:selectOptions value="{!Valuesr}" />
        </apex:SelectList>
</apex:actionRegion>
    
    <apex:outputLabel value="District" />
    <apex:selectList value="{!dist}" size="1" id="dist" required="true">
        <apex:selectOptions value="{!values}">
        <apex:actionsupport event="onchange" rerender="SalesId"/>
 
        </apex:selectOptions>
    
    </apex:selectList>

</apex:form>
</apex:pageBlock>

</apex:page>

And following is the controller

public with sharing class UserStatsController {

    public string Regn {get; set;}
    public string dist {get; set;}    

    public list <SelectOption> getValuesr()
    {
    list <selectoption> lsreg = new List<selectoption> ();
    for (User_Stats__C Regn : [SELECT Region__c FROM User_Stats__C where Region__c != null and Region__c != 0 and District__c != null and District__c != '0' limit 10])
    {
    lsreg.add(new selectoption(string.valueOf(Regn.Region__c), string.valueOf(Regn.Region__c)));
    }
    return lsreg;
    }
    
            public list <SelectOption> getValues()
    {
    list <selectoption> ls = new List<selectoption> ();
    for (User_Stats__C dist : [SELECT District__c FROM User_Stats__C where Region__c =: integer.valueof(apexpages.currentpage().getparameters().get('Regn')) and District__c != '' and Region__c != null and Region__c != 0 limit 10])
    {
    ls.add(new selectoption(dist.District__c, dist.District__c));
    }
    return ls;
    }}

Thanks in advance!

Following is the code for VF:

<apex:page Controller="UserStatsController">
<apex:sectionHeader title="Goal Revision Dashboard" subtitle="District View"/>
<apex:pageBlock title="User Stats">
<apex:form >
 <apex:outputLabel value="Region" />
    <apex:selectList value="{!regn}" size="1" id="Region" required="true">
        <apex:selectOptions value="{!Valuesr}" />
        <apex:actionSupport event="onchange" reRender="districtSelect"/>
    </apex:SelectList>
<apex:outputPanel id="districtSelect">
    <apex:outputLabel value="District"/>
    <apex:selectList value="{!dist}" size="1" id="dist" required="true">
        <apex:selectOptions value="{!Values}"/>
    </apex:selectList>
    </apex:outputPanel>
</apex:page>

And following is the controller

public with sharing class UserStatsController {

public string regn {get; set;}
public string dist {get; set;}    

public list <SelectOption> getValuesr()
{
    list <selectoption> lsreg = new List<selectoption> ();
    lsreg.add(new SelectOption('', '--None--'));
    for (User_Stats__C Rgn : [SELECT Region__c FROM User_Stats__C where Region__c != null and Region__c != 0 and District__c != null and District__c != '0' limit 10])
    {
        lsreg.add(new selectoption(string.valueOf(Rgn.Region__c), string.valueOf(Rgn.Region__c)));
    }
    return lsreg;
}

public list <SelectOption> getValues()
{
    list <selectoption> ls = new List<selectoption> ();
    ls.add(new SelectOption('', '--None--'));
    Integer regnInt = (regn!=null) ? Integer.valueOf(regn) : -1;
    for (User_Stats__C dist : [SELECT District__c FROM User_Stats__C where Region__c =: regnInt and District__c != '' and Region__c != null and Region__c != 0 limit 10])
    {
        ls.add(new selectoption(dist.District__c, dist.District__c));
    }
    return ls;
} 
}

Thanks.

Source Link
Robin
  • 555
  • 4
  • 18
  • 34

VisualForce not able to render select list

I think I am missing something basic. I have two select lists: Region and District. Based on region selection, the district values should get updated.

When I try to save, the page gets saved but returns a Visualforce error: System.NullPointerException: Argument 1 cannot be null

Class.UserStatsController.getValues: line 20, column 1

Following is the code for visual page:

<apex:page Controller="UserStatsController">

<apex:sectionHeader title="Goal Revision Dashboard" subtitle="District View"/> <apex:pageBlock title="User Stats">

<apex:form > <apex:actionRegion > <apex:actionFunction name="RefreshRgn" rerender="dist, District" > <apex:param name="firstParam" assignTo="{!Regn}" value="" /> </apex:actionFunction>

        <apex:outputLabel value="Region" />
        <apex:selectList value="{!Regn}" size="1" id="Region" required="true" onchange="RefreshRgn(this.value)">
            <apex:selectOptions value="{!Valuesr}" />
        </apex:SelectList>
</apex:actionRegion>
    
    <apex:outputLabel value="District" />
    <apex:selectList value="{!dist}" size="1" id="dist" required="true">
        <apex:selectOptions value="{!values}">
        <apex:actionsupport event="onchange" rerender="SalesId"/>

        </apex:selectOptions>
    
    </apex:selectList>

</apex:form>
</apex:pageBlock>

</apex:page>

And following is the controller

public with sharing class UserStatsController {

    public string Regn {get; set;}
    public string dist {get; set;}    

    public list <SelectOption> getValuesr()
    {
    list <selectoption> lsreg = new List<selectoption> ();
    for (User_Stats__C Regn : [SELECT Region__c FROM User_Stats__C where Region__c != null and Region__c != 0 and District__c != null and District__c != '0' limit 10])
    {
    lsreg.add(new selectoption(string.valueOf(Regn.Region__c), string.valueOf(Regn.Region__c)));
    }
    return lsreg;
    }
    
            public list <SelectOption> getValues()
    {
    list <selectoption> ls = new List<selectoption> ();
    for (User_Stats__C dist : [SELECT District__c FROM User_Stats__C where Region__c =: integer.valueof(apexpages.currentpage().getparameters().get('Regn')) and District__c != '' and Region__c != null and Region__c != 0 limit 10])
    {
    ls.add(new selectoption(dist.District__c, dist.District__c));
    }
    return ls;
    }}

Thanks in advance!