You need to sign in to do that
Don't have an account?
Radhika pawar 5
Error: System.NullPointerException: Argument 1 cannot be null .for soql Query
Below is my scenario:
There are 3 pick lists comming from parent object(School_List) in Child object(RI_Follow_Up_School_Report_Card).
When i will select value from first picklist (National) :Example (India) then 2nd picklist (State) should get refresh and show all states.
And simmilarly when i will Select State Name from 2nd picklist (Example -Maharashtra) then 3rd picklist (BRG Name) should get refresh and show all BRG Names
from that particular state. Here I am getting NullPointerException error for below query. And I am getting this error only when I am running this in production, however it is running succefully on Sandbox.
public List<SelectOption> getAttStates() {
List<SelectOption>lstSchoolStates = new List<SelectOption>();
AggregateResult []ar = [Select School_List__r.State__c State from RI_Follow_Up_School_Report_Card__c where FW_Submission_No__c != null AND FW_Submission_No__c != 0 AND School_List__r.National__c =: strNational GROUP BY School_List__r.State__c];
lstSchoolStates .add(new SelectOption('','-None-'));
for(AggregateResult temp: ar) {
lstSchoolStates.add(new SelectOption(String.valueOf(temp.get('State')),String.valueOf(temp.get('State'))));
}
return lstSchoolStates ;
}
public List<SelectOption> getAttBRG() {
List<SelectOption> lstBRG = new List<SelectOption>();
String query = 'Select BRG_Camp_1__r.Name brg, BRG_Camp_1__c id from RI_Follow_Up_School_Report_Card__c where School_List__r.state__c =: strState AND School_List__r.National__c =: strNational';
query += ' GROUP BY BRG_Camp_1__c, BRG_Camp_1__r.Name';
AggregateResult []ar = Database.query(query);
lstBRG .add(new SelectOption('','-None-'));
for(AggregateResult temp: ar) {
lstBRG.add(new SelectOption(String.valueOf(temp.get('id')),String.valueOf(temp.get('brg'))));
}
Below is the complete code. Please help
Apex Class:
public with sharing class ctrltestfwrd
{
public List<SelectOption> lstNational {get;set;}
public List<List<String>> lstReport {get;set;}
public List<List<String>> lstReport1 {get;set;}
public List<List<String>> lstReport2 {get;set;}
public List<RI_Follow_Up_School_Report_Card__c> lstSchool = new List<RI_Follow_Up_School_Report_Card__c>();
public String strState {get;set;}
public String strBlocks {get;set;}
public String strNational {get;set;}
public String strBRG {get;set;}
public ctrltestfwrd () {
strState = '';
strBlocks = '';
strNational = '';
strBRG = '';
lstNational = new List<SelectOption>();
lstNational.add(new SelectOption('', '- - None - -'));
Schema.DescribeFieldResult F = RI_School_List__c.National__c.getDescribe();
for (Schema.PicklistEntry temp : F.getPicklistValues()) {
lstNational.add(new SelectOption(temp.getValue(), temp.getLabel()));
}
lstReport = new List<List<String>> ();
lstReport1 = new List<List<String>> ();
lstReport2 = new List<List<String>> ();
if (strNational != '' && strNational != null) {}
else{loadReport();}
}
public List<SelectOption> getAttStates() {
List<SelectOption>lstSchoolStates = new List<SelectOption>();
AggregateResult []ar = [Select School_List__r.State__c State from RI_Follow_Up_School_Report_Card__c where FW_Submission_No__c != null AND FW_Submission_No__c != 0 AND School_List__r.National__c =: strNational GROUP BY School_List__r.State__c];
lstSchoolStates .add(new SelectOption('','-None-'));
for(AggregateResult temp: ar) {
lstSchoolStates.add(new SelectOption(String.valueOf(temp.get('State')),String.valueOf(temp.get('State'))));
}
return lstSchoolStates ;
}
public List<SelectOption> getAttBRG() {
List<SelectOption> lstBRG = new List<SelectOption>();
String query = 'Select BRG_Camp_1__r.Name brg, BRG_Camp_1__c id from RI_Follow_Up_School_Report_Card__c where School_List__r.state__c =: strState AND School_List__r.National__c =: strNational';
query += ' GROUP BY BRG_Camp_1__c, BRG_Camp_1__r.Name';
AggregateResult []ar = Database.query(query);
lstBRG .add(new SelectOption('','-None-'));
for(AggregateResult temp: ar) {
lstBRG.add(new SelectOption(String.valueOf(temp.get('id')),String.valueOf(temp.get('brg'))));
}
return lstBRG ;
}
public pagereference loadReport()
{return null;
}}
VF page Code:
<apex:page controller="ctrltestfwrd" showHeader="false" sidebar="false">
<table border="0" cellspacing="2" cellpadding="" align="left" width="100%">
<tr>
<td width="17%"><apex:image url="{!$Resource.Pratham_Logo_png}" height="60" width="220" /></td>
<td><center><font face="Calibri" size="6" color="black"><b>Read India Reports - 2014</b></font></center>
</td>
<td align="right" width="17%"><a href="http://pratham.force.com/RIReports2014"><apex:image url="{!$Resource.Home}" height="50" width="50"/></a> </td>
</tr>
</table>
<hr color="gold" size="4"/>
<!-- Begin Default Content REMOVE THIS -->
<center><font face="calibri" size="5" color="#FF6633"><b>Language: Reading Analysis</b></font><br/>
<font face="calibri" size="3.5" color="Blue"> <b> Reading Learning Level Analysis across Camps</b><br/><br/></font>
</center>
<apex:form id="frm">
<apex:pageBlock >
<center>
<apex:SelectList value="{!strNational}" size="1" multiselect="false" style="width:150px;">
<font face="calibri" size="3"><b>National :</b> </font><apex:SelectOptions value="{!lstNational}"/>
<apex:actionsupport event="onchange" rerender="child_states"/>
</apex:SelectList>
<apex:SelectList value="{!strState}" size="1" multiselect="false" style="width:150px;" id="child_states">
<font face="calibri" size="3"><b>Select State :</b> </font><apex:SelectOptions value="{!AttStates}"/>
<apex:actionsupport event="onchange" rerender="child_brg,child_blocks"/>
</apex:SelectList>
<!--<apex:SelectList value="{!strBlocks}" size="1" multiselect="false" style="width:150px;" id="child_blocks">
<font face="calibri" size="3"><b>Select Block :</b> </font><apex:SelectOptions value="{!AttBlocks}"/>
</apex:SelectList>--><br/>
<hr color="#000" align="center" width="60%"/>
<apex:SelectList value="{!strBRG}" size="1" multiselect="false" style="width:150px;" id="child_brg">
<font face="calibri" size="3"><b>Select BRG :</b> </font><apex:SelectOptions value="{!AttBrg}"/>
</apex:SelectList>
<br/><br/>
<apex:commandButton value="Go" action="{!loadReport}" status="Status" reRender="frm, panel2, campmodel" style="width:70px; font-family: 'candara'; font-size: 12pt; color: #0000ff; background-color: #FFFFC0; border: 2pt ridge gold" oncomplete="drawChart();" />
<apex:actionStatus id="Status">
<apex:facet name="start">
<img style="padding-left:10px;" src="/img/loading.gif" />
</apex:facet>
</apex:actionStatus>
</center><br/>
<center><b><i><apex:outputText value="[ Note: This report is updated up to {!today()} ]" style="font-family:calibri;font-size:14px;color:black;font-weight:bold;"/></i></b></center>
</apex:pageblock>
</apex:form>
</apex:page>
There are 3 pick lists comming from parent object(School_List) in Child object(RI_Follow_Up_School_Report_Card).
When i will select value from first picklist (National) :Example (India) then 2nd picklist (State) should get refresh and show all states.
And simmilarly when i will Select State Name from 2nd picklist (Example -Maharashtra) then 3rd picklist (BRG Name) should get refresh and show all BRG Names
from that particular state. Here I am getting NullPointerException error for below query. And I am getting this error only when I am running this in production, however it is running succefully on Sandbox.
public List<SelectOption> getAttStates() {
List<SelectOption>lstSchoolStates = new List<SelectOption>();
AggregateResult []ar = [Select School_List__r.State__c State from RI_Follow_Up_School_Report_Card__c where FW_Submission_No__c != null AND FW_Submission_No__c != 0 AND School_List__r.National__c =: strNational GROUP BY School_List__r.State__c];
lstSchoolStates .add(new SelectOption('','-None-'));
for(AggregateResult temp: ar) {
lstSchoolStates.add(new SelectOption(String.valueOf(temp.get('State')),String.valueOf(temp.get('State'))));
}
return lstSchoolStates ;
}
public List<SelectOption> getAttBRG() {
List<SelectOption> lstBRG = new List<SelectOption>();
String query = 'Select BRG_Camp_1__r.Name brg, BRG_Camp_1__c id from RI_Follow_Up_School_Report_Card__c where School_List__r.state__c =: strState AND School_List__r.National__c =: strNational';
query += ' GROUP BY BRG_Camp_1__c, BRG_Camp_1__r.Name';
AggregateResult []ar = Database.query(query);
lstBRG .add(new SelectOption('','-None-'));
for(AggregateResult temp: ar) {
lstBRG.add(new SelectOption(String.valueOf(temp.get('id')),String.valueOf(temp.get('brg'))));
}
Below is the complete code. Please help
Apex Class:
public with sharing class ctrltestfwrd
{
public List<SelectOption> lstNational {get;set;}
public List<List<String>> lstReport {get;set;}
public List<List<String>> lstReport1 {get;set;}
public List<List<String>> lstReport2 {get;set;}
public List<RI_Follow_Up_School_Report_Card__c> lstSchool = new List<RI_Follow_Up_School_Report_Card__c>();
public String strState {get;set;}
public String strBlocks {get;set;}
public String strNational {get;set;}
public String strBRG {get;set;}
public ctrltestfwrd () {
strState = '';
strBlocks = '';
strNational = '';
strBRG = '';
lstNational = new List<SelectOption>();
lstNational.add(new SelectOption('', '- - None - -'));
Schema.DescribeFieldResult F = RI_School_List__c.National__c.getDescribe();
for (Schema.PicklistEntry temp : F.getPicklistValues()) {
lstNational.add(new SelectOption(temp.getValue(), temp.getLabel()));
}
lstReport = new List<List<String>> ();
lstReport1 = new List<List<String>> ();
lstReport2 = new List<List<String>> ();
if (strNational != '' && strNational != null) {}
else{loadReport();}
}
public List<SelectOption> getAttStates() {
List<SelectOption>lstSchoolStates = new List<SelectOption>();
AggregateResult []ar = [Select School_List__r.State__c State from RI_Follow_Up_School_Report_Card__c where FW_Submission_No__c != null AND FW_Submission_No__c != 0 AND School_List__r.National__c =: strNational GROUP BY School_List__r.State__c];
lstSchoolStates .add(new SelectOption('','-None-'));
for(AggregateResult temp: ar) {
lstSchoolStates.add(new SelectOption(String.valueOf(temp.get('State')),String.valueOf(temp.get('State'))));
}
return lstSchoolStates ;
}
public List<SelectOption> getAttBRG() {
List<SelectOption> lstBRG = new List<SelectOption>();
String query = 'Select BRG_Camp_1__r.Name brg, BRG_Camp_1__c id from RI_Follow_Up_School_Report_Card__c where School_List__r.state__c =: strState AND School_List__r.National__c =: strNational';
query += ' GROUP BY BRG_Camp_1__c, BRG_Camp_1__r.Name';
AggregateResult []ar = Database.query(query);
lstBRG .add(new SelectOption('','-None-'));
for(AggregateResult temp: ar) {
lstBRG.add(new SelectOption(String.valueOf(temp.get('id')),String.valueOf(temp.get('brg'))));
}
return lstBRG ;
}
public pagereference loadReport()
{return null;
}}
VF page Code:
<apex:page controller="ctrltestfwrd" showHeader="false" sidebar="false">
<table border="0" cellspacing="2" cellpadding="" align="left" width="100%">
<tr>
<td width="17%"><apex:image url="{!$Resource.Pratham_Logo_png}" height="60" width="220" /></td>
<td><center><font face="Calibri" size="6" color="black"><b>Read India Reports - 2014</b></font></center>
</td>
<td align="right" width="17%"><a href="http://pratham.force.com/RIReports2014"><apex:image url="{!$Resource.Home}" height="50" width="50"/></a> </td>
</tr>
</table>
<hr color="gold" size="4"/>
<!-- Begin Default Content REMOVE THIS -->
<center><font face="calibri" size="5" color="#FF6633"><b>Language: Reading Analysis</b></font><br/>
<font face="calibri" size="3.5" color="Blue"> <b> Reading Learning Level Analysis across Camps</b><br/><br/></font>
</center>
<apex:form id="frm">
<apex:pageBlock >
<center>
<apex:SelectList value="{!strNational}" size="1" multiselect="false" style="width:150px;">
<font face="calibri" size="3"><b>National :</b> </font><apex:SelectOptions value="{!lstNational}"/>
<apex:actionsupport event="onchange" rerender="child_states"/>
</apex:SelectList>
<apex:SelectList value="{!strState}" size="1" multiselect="false" style="width:150px;" id="child_states">
<font face="calibri" size="3"><b>Select State :</b> </font><apex:SelectOptions value="{!AttStates}"/>
<apex:actionsupport event="onchange" rerender="child_brg,child_blocks"/>
</apex:SelectList>
<!--<apex:SelectList value="{!strBlocks}" size="1" multiselect="false" style="width:150px;" id="child_blocks">
<font face="calibri" size="3"><b>Select Block :</b> </font><apex:SelectOptions value="{!AttBlocks}"/>
</apex:SelectList>--><br/>
<hr color="#000" align="center" width="60%"/>
<apex:SelectList value="{!strBRG}" size="1" multiselect="false" style="width:150px;" id="child_brg">
<font face="calibri" size="3"><b>Select BRG :</b> </font><apex:SelectOptions value="{!AttBrg}"/>
</apex:SelectList>
<br/><br/>
<apex:commandButton value="Go" action="{!loadReport}" status="Status" reRender="frm, panel2, campmodel" style="width:70px; font-family: 'candara'; font-size: 12pt; color: #0000ff; background-color: #FFFFC0; border: 2pt ridge gold" oncomplete="drawChart();" />
<apex:actionStatus id="Status">
<apex:facet name="start">
<img style="padding-left:10px;" src="/img/loading.gif" />
</apex:facet>
</apex:actionStatus>
</center><br/>
<center><b><i><apex:outputText value="[ Note: This report is updated up to {!today()} ]" style="font-family:calibri;font-size:14px;color:black;font-weight:bold;"/></i></b></center>
</apex:pageblock>
</apex:form>
</apex:page>
Sagar Pareek
As you have mentioned that code is running on SB with out this issue have you check your records in the database?Do where clause is getting satisfied?