I have a visual force page that calls a custom object controller extension, as below:

Custom Controller

public class ProjectApproval{

    ApexPages.StandardController controller;
        public ProjectApproval(ApexPages.StandardController con){
                controller = con;

    ResearchProject__c project {get; set;}

    public PageReference save(){
         String base = URL.getSalesforceBaseUrl().toExternalForm();
         Pagereference pr = New PageReference(base + '/ApprovalSuccess');
         return pr;

    public void declTick(){
        project.Head_of_School_Appr__c = false;

Visual Force Page

<apex:inputCheckbox value="{!ResearchProject__c.Head_of_School_Decline__c}">
    <apex:actionSupport event="onchange" action="{!declTick}" reRender="headAppr" />

When I call the declTick() function, I get a Null reference error. I assume I am not instantiating the project object correctly, but I cannot work out how. Any help would be appreciated, thanks.

1 Answer 1


You are getting that exception because you are using project variable in declTick method which is not yet initialized i.e. it is still null. And when you try to perform operations on null object, you will get Attempt to dereference a null object exception.

As this is an extension controller, you can assign the standard controller instance to the instance that you are working with in delTick method so that it copies all the field values from standard instance to your instance. You can do that in constructor by using the standard controller's getRecord method.

public ProjectApproval(ApexPages.StandardController con){
    controller = con;
    project = (ResearchProject__c)con.getRecord();

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .