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
nilanginilangi 

I am creating simple page with one inputfield and its value is accessed in apex code.

<apex:page controller="resulttab" >
<apex:form >
<apex:pageBlock >
 <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!next}" rerender="error"/>
            </apex:pageBlockButtons>
 <apex:inputField value="{!res.examid__c}"/>
 </apex:pageBlock>
 </apex:form>
</apex:page>

 

 

 

public class resulttab
{
   public result__c res {get; set;}
   public String a {get; set;}
   
   public String save()
   {
       a = res.examid__c;
       return a;
       next();
   }
   
   public List<result__c> next()
   {
   return [SELECT name__c,college_name__c,branch__c,year__c,semester__c,clgno__c,total__c,status__c,percent__c,marks__c,examid__c FROM result__c WHERE examid__c = a ];
   }
}

 

 

error:

 Error Message: System.NullPointerException: Attempt to de-referen
bob_buzzardbob_buzzard

This is because your save method hasn't been executed by the time your next method is executed.

 

You can simply use the value in the next method,

 

E.g.

 

public List<result__c> next()
   {
   return [SELECT name__c,college_name__c,branch__c,year__c,semester__c,clgno__c,total__c,status__c,percent__c,marks__c,examid__c FROM result__c WHERE examid__c = :res.examid__c ];
   }