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
SasidSasid 

System.NullPointerException: Attempt to de-reference a null object Class.SessionControllerExtension.<init>: line 12, column 1

public with sharing class SessionControllerExtension {

    public Integer counter {get; set;}

    public blob picture { get; set; }
    public String errorMessage { get; set; }

    private final Session__c session;
    private ApexPages.StandardController stdController;

    public SessionControllerExtension(ApexPages.StandardController controller) {
        this.session = (Session__c)stdController.getRecord();
        this.stdController = stdController;
        counter = 0;
    }

    public void increment() {
        counter++;
    }
}
Best Answer chosen by Sasid
Amit Chaudhary 8Amit Chaudhary 8
Update your class like below
public with sharing class SessionControllerExtension {

    public Integer counter {get; set;}

    public blob picture { get; set; }
    public String errorMessage { get; set; }

    private final Session__c session;
    private ApexPages.StandardController stdController;

    public SessionControllerExtension(ApexPages.StandardController controller) {
        this.session = (Session__c)controller.getRecord();
        counter = 0;
    }

    public void increment() {
        counter++;
    }
}

 

All Answers

swati_sehrawatswati_sehrawat
Hello, 

Are you using this class with visualforcepage, i guess you are missing "id" parameter in URL for session record.

getRecord()
Returns the record that is currently in context, based on the value of the id query string parameter in the Visualforce page URL.
Amit Chaudhary 8Amit Chaudhary 8
Update your class like below
public with sharing class SessionControllerExtension {

    public Integer counter {get; set;}

    public blob picture { get; set; }
    public String errorMessage { get; set; }

    private final Session__c session;
    private ApexPages.StandardController stdController;

    public SessionControllerExtension(ApexPages.StandardController controller) {
        this.session = (Session__c)controller.getRecord();
        counter = 0;
    }

    public void increment() {
        counter++;
    }
}

 
This was selected as the best answer