Below is my controller class code

public Account acctObj {
    set {
        new Account();
public boolean checkMessageFlag {
    set {
        checkMessageFlag = true;
public PageReference updateViewStateForCreditCheckMessage() {
    if(acctObj.Decline_Credit_Check__c == true) {
        checkMessageFlag = false;
    return null;

And below is the markup for my Visualforce Page

<apex:outputLabel id="creditCheckMessageId" value="*Credit Check has not been performed"
                            style="font-size: inherit;color:red;" rendered="{!checkMessageFlag}" ></apex:outputLabel>
                    <apex:outputLabel ><apex:inputField value="{!acctObj.Decline_Credit_Check__c}">
                     <apex:actionSupport event="onchange"
                    </apex:inputField>&nbsp;&nbsp;Decline Credit Check </apex:outputLabel>

I am trying to remove the text when the check box is checked. but whenever I try to check the box i get an error saying "Attempt to dereference a null object". Any hep in this ?


1 Answer 1


You really must read up on and understand Apex Properties. It's too long to quote at length, but here's the basic idea:

public class BasicProperty {
   public integer prop {
      get { return prop; }
      set { prop = value; }

The problem with your code is you never actually instantiate your acctObj property. The correct way would be to either put it in the constructor (preferred) or use the getter, since you're never calling the setter anywhere.


public Account acctObj { get; private set; }
public MyController(/*any parameters*/)
    accctObj = new Account();


public Account acctObj
        if (acctObj == null) acctObj = new Account();

        // you need to perform an assignment somewhere
        // as in the above line
        // this pattern is called Lazy Loading

        return acctObj;
    private set;
  • It does not gives the error but it also does not shows the output label when I uncheck the checkbox, which was the functionality I was trying to achieve to show the text based on checkbox value Commented Jan 6, 2017 at 3:13
  • Well, that sounds like a separate question, as this is the core issue you had with your code. If your understanding is at this level, you should strongly consider working through all the related Trailhead modules you can find.
    – Adrian Larson
    Commented Jan 6, 2017 at 3:14
  • @AdrianLarson Did you review their previous questions...?
    – sfdcfox
    Commented Jan 6, 2017 at 3:15
  • No I didn't know they had been asking a series.
    – Adrian Larson
    Commented Jan 6, 2017 at 3:16

You must log in to answer this question.

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