You need to sign in to do that
Don't have an account?
veeru_pari
VFError
Hi ,
Ia m getting the following error while runnung the code it is @line 26 in my code i have marked the line 26 please help me on this to solve the error
Visualforce Error
Help for this Page
System.NullPointerException: Argument 1 cannot be null
Class.FAQCu.getSearch: line 26, column 1 )
In the above code the line 26 is marked below it is in getSearch method below is the code where i have hilighted line 26 in the code
public class FAQCu {
public String selectedValue {get;set;}
public List<SelectOption> getUserType()
{
List<SelectOption> options = new List<SelectOption>();
Schema.DescribeFieldResult fieldResult =FAQ__c.Users__c.getDescribe();
List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
// options.add(new SelectOption('All','All'));
for( Schema.PicklistEntry f : ple)
{
options.add(new SelectOption(f.getLabel(), f.getValue()));
}
return options;
}
public List<FAQ__c> getSearch(){
System.debug('====selectedValue===='+selectedValue); // You will get the Selected Value here
List<FAQ__c> temp = new List<FAQ__c>();
String queryString;
if(selectedValue=='AllUsers')
queryString='SELECT Users__c,Question__c,Answer__cfrom FAQ__c WHERE Users__c =AllUsers';
else if(selectedValue=='InternalUsers')
queryString='SELECT Users__c,Question__c,Answer__c from FAQ__c WHERE Users__c =InternalUsers';
else if(selectedValue=='ExternalUsers')
queryString='SELECT Users__c,Question__c,Answer__c from FAQ__c WHERE Users__c =ExternalUsers';
26line// temp = Database.query(queryString);
return temp;
}
}
VF code
<apex:page controller="FAQCu" id="theRepeat">
<apex:form >
<apex:selectList id="users" value="{!selectedValue}" size="1" required="true">
<apex:selectOptions value="{!userType}"/>
<apex:actionSupport event="onchange" rerender="questions"/>
</apex:selectList>
<apex:dataTable value="{!search}" var="faq" id="questions">
<apex:column >
<apex:outputText value="{!faq.Question__c}"/>
</apex:column>
<apex:column >
<apex:outputText value="{!faq.Answer__c}"/>
</apex:column>
</apex:dataTable>
</apex:form>
</apex:page>
Thanks
Veeraiah
Ia m getting the following error while runnung the code it is @line 26 in my code i have marked the line 26 please help me on this to solve the error
Visualforce Error
Help for this Page
System.NullPointerException: Argument 1 cannot be null
Class.FAQCu.getSearch: line 26, column 1 )
In the above code the line 26 is marked below it is in getSearch method below is the code where i have hilighted line 26 in the code
public class FAQCu {
public String selectedValue {get;set;}
public List<SelectOption> getUserType()
{
List<SelectOption> options = new List<SelectOption>();
Schema.DescribeFieldResult fieldResult =FAQ__c.Users__c.getDescribe();
List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
// options.add(new SelectOption('All','All'));
for( Schema.PicklistEntry f : ple)
{
options.add(new SelectOption(f.getLabel(), f.getValue()));
}
return options;
}
public List<FAQ__c> getSearch(){
System.debug('====selectedValue===='+selectedValue); // You will get the Selected Value here
List<FAQ__c> temp = new List<FAQ__c>();
String queryString;
if(selectedValue=='AllUsers')
queryString='SELECT Users__c,Question__c,Answer__cfrom FAQ__c WHERE Users__c =AllUsers';
else if(selectedValue=='InternalUsers')
queryString='SELECT Users__c,Question__c,Answer__c from FAQ__c WHERE Users__c =InternalUsers';
else if(selectedValue=='ExternalUsers')
queryString='SELECT Users__c,Question__c,Answer__c from FAQ__c WHERE Users__c =ExternalUsers';
26line// temp = Database.query(queryString);
return temp;
}
}
VF code
<apex:page controller="FAQCu" id="theRepeat">
<apex:form >
<apex:selectList id="users" value="{!selectedValue}" size="1" required="true">
<apex:selectOptions value="{!userType}"/>
<apex:actionSupport event="onchange" rerender="questions"/>
</apex:selectList>
<apex:dataTable value="{!search}" var="faq" id="questions">
<apex:column >
<apex:outputText value="{!faq.Question__c}"/>
</apex:column>
<apex:column >
<apex:outputText value="{!faq.Answer__c}"/>
</apex:column>
</apex:dataTable>
</apex:form>
</apex:page>
Thanks
Veeraiah
You are getting this error because you haven't given by default value to "selectedValue" string variable.
Please set value for it first In your constructor.
see below updated class code.
public class FAQCu {
public String selectedValue {get;set;}
public FAQCu(){
selectedValue = 'AllUsers';
}
public List<SelectOption> getUserType(){
List<SelectOption> options = new List<SelectOption>();
Schema.DescribeFieldResult fieldResult =FAQ__c.Users__c.getDescribe();
List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
// options.add(new SelectOption('All','All'));
for( Schema.PicklistEntry f : ple){
options.add(new SelectOption(f.getLabel(), f.getValue()));
}
return options;
}
public List<FAQ__c> getSearch(){
System.debug('====selectedValue===='+selectedValue); // You will get the Selected Value here
List<FAQ__c> temp = new List<FAQ__c>();
String queryString;
if(selectedValue=='AllUsers')
queryString='SELECT Users__c,Question__c,Answer__c from FAQ__c WHERE Users__c = \'AllUsers\'';
else if(selectedValue=='InternalUsers')
queryString='SELECT Users__c,Question__c,Answer__c from FAQ__c WHERE Users__c = \'InternalUsers\'';
else if(selectedValue=='ExternalUsers')
queryString='SELECT Users__c,Question__c,Answer__c from FAQ__c WHERE Users__c = \'ExternalUsers\'';
//26line//
temp = Database.query(queryString);
return temp;
}
}
Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator & Advanced Administrator & Sales cloud consultant
My Blog:- http://mrjavascript.blogspot.in/