function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
veeru_pariveeru_pari 

Null pointer Exception

Hi ,
I am getting this error while using the below code in vf(System.NullPointerException: Argument 1 cannot be null )
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__cfrom FAQ__c WHERE Users__c = \'InternalUsers\' ';
   else if(selectedValue=='ExternalUsers')
queryString='SELECT Users__c,Question__c,Answer__cfrom FAQ__c WHERE Users__c = \'InternalUsers\' ';
/Line 26/temp = Database.query(queryString);
      return temp;
      }
    }
VF
apex:page controller="FAQCu" id="theRepeat">
<apex:form >

<apex:selectList id="users" value="{!selectedValue}" size="1" required="true">
  <apex:selectOptions value="{!userType}"/>
</apex:selectList>
</apex:form>
<apex:repeat value="{!search}" var="string" id="theRepeat">
<apex:outputText value="{!string}" id="theValue"/><br/>
    </apex:repeat>
</apex:page>
Maros SitkoMaros Sitko
You should use brackets. this is your method
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__cfrom FAQ__c WHERE Users__c = \'InternalUsers\' ';
   } else if(selectedValue=='ExternalUsers') {
queryString='SELECT Users__c,Question__c,Answer__cfrom FAQ__c WHERE Users__c = \'InternalUsers\' ';
}
/Line 26/temp = Database.query(queryString);
      return temp;
      }

issue is that you do not have cover case when selectedValue is NULL, so queryString is empty. this method is inoked during first render of the page, and queryString is empty, selectedValue is null too. You can add condition before line 26
if(queryString != null) {
/Line 26/temp = Database.query(queryString);
}