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
Vidya RaniVidya Rani 

Visualforce Error : External entry point

I am trying to use multiselect picklist on vf page and show results based on selected values via button click. Getting Error :
" Visualforce Error
System.NullPointerException: Attempt to de-reference a null object 
External entry point "


Any suggestions will really help. Thanks in advance.

Code Piece:
<apex:page controller="SinglepicklistforMyBook" action="{!autoRun}" sidebar="false">

    <apex:form >
     <table align="center" cellpadding="15" > 
    <td>Select Property Type :-</td>
         <td><apex:selectList size="4" value="{!SelectValue}" multiselect="true">
            <apex:selectOptions value="{!statusOptions}"/>       

        </apex:selectList></td>        
       <tr> <td>List of Selected Values For Books of Type:</td> 
  <td><apex:outputText label="You have selected:" value="{!SelectValue}" /> </td> </tr>
          <div align="center" draggable="false" > 
            <apex:commandButton style="float:centre" value="Show Result" onclick="{!ShowResult}"/>
            <apex:actionSupport reRender="refresh" event="onkeyup" />
            </div>
                 <apex:pageBlock >
   <apex:pageblockTable align="center" cellpadding="15" value="{!ShowResult}" var="O" title="List of Selected Books">
       <apex:column value="{!O.Name}"/>
       <apex:column value="{!O.Status_Book__c}"/>
       </apex:pageblockTable> 
  </apex:pageBlock>   
        </table>
    </apex:form>
</apex:page>
*************************
Controller
*************************
public with sharing class SinglepicklistforMyBook {

public List<SelectOption> statusOptions { get;set; }
public List<String> selectValue {get;set;} //for multiselect
     
    //    public string selectValue { get;set; }  //in case multiselect =false
 List<Book__c> showresult;
    public List<Book__c> getShowResult() {
 
      //showresult=  [Select Name, Status_Book__c from Book__c where Status_Book__c = :selectValue ]; // for multiselect = false
        showresult=  [Select Name, Status_Book__c from Book__c where Status_Book__c IN :selectValue]; //for multiselect
        return showresult;
    }

public void autoRun()

{

    Schema.DescribeFieldResult statusFieldDescription = Book__c.Status_Book__c.getDescribe();

    statusOptions = new list<SelectOption>();     

    for (Schema.Picklistentry picklistEntry : statusFieldDescription.getPicklistValues())

    {

        statusOptions.add(new SelectOption(pickListEntry.getValue(),pickListEntry.getLabel()));

    }

}

}
Best Answer chosen by Vidya Rani
Raj VakatiRaj Vakati
Use this code
public with sharing class SinglepicklistforMyBook {
    
    public List<SelectOption> statusOptions { get;set; }
    public List<String> selectValue {get;set;} //for multiselect
    
    public SinglepicklistforMyBook(){
        statusOptions = new List<SelectOption>();
        
    }
    
    //    public string selectValue { get;set; }  //in case multiselect =false
    List<Book__c> showresult;
    public List<Book__c> getShowResult() {
        if(selectValue!=null){
        //showresult=  [Select Name, Status_Book__c from Book__c where Status_Book__c = :selectValue ]; // for multiselect = false
        showresult=  [Select Name, Status_Book__c from Book__c where Status_Book__c IN :selectValue]; //for multiselect
        return showresult;
        }else{
            return null ;
        }
    }
    
    public void autoRun()
        
    {
        
        Schema.DescribeFieldResult statusFieldDescription = Book__c.Status_Book__c.getDescribe();
        
        statusOptions = new list<SelectOption>();     
        
        for (Schema.Picklistentry picklistEntry : statusFieldDescription.getPicklistValues())
            
        {
            
            statusOptions.add(new SelectOption(pickListEntry.getValue(),pickListEntry.getLabel()));
            
        }
        
    }
    
}

 

All Answers

Raj VakatiRaj Vakati
Use this code
public with sharing class SinglepicklistforMyBook {
    
    public List<SelectOption> statusOptions { get;set; }
    public List<String> selectValue {get;set;} //for multiselect
    
    public SinglepicklistforMyBook(){
        statusOptions = new List<SelectOption>();
        
    }
    
    //    public string selectValue { get;set; }  //in case multiselect =false
    List<Book__c> showresult;
    public List<Book__c> getShowResult() {
        if(selectValue!=null){
        //showresult=  [Select Name, Status_Book__c from Book__c where Status_Book__c = :selectValue ]; // for multiselect = false
        showresult=  [Select Name, Status_Book__c from Book__c where Status_Book__c IN :selectValue]; //for multiselect
        return showresult;
        }else{
            return null ;
        }
    }
    
    public void autoRun()
        
    {
        
        Schema.DescribeFieldResult statusFieldDescription = Book__c.Status_Book__c.getDescribe();
        
        statusOptions = new list<SelectOption>();     
        
        for (Schema.Picklistentry picklistEntry : statusFieldDescription.getPicklistValues())
            
        {
            
            statusOptions.add(new SelectOption(pickListEntry.getValue(),pickListEntry.getLabel()));
            
        }
        
    }
    
}

 
This was selected as the best answer
Vidya RaniVidya Rani
Thanks :) It works. Just one question : Are lines 6 and 7 important ? It works without that after putting showresult query in if condition.
Raj VakatiRaj Vakati
No need .. But as a prince its good to initialized all the variable on the constructor