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
deux4everdeux4ever 

Attempt to de-reference a null object (Visualforce and Flow)

When I try to run my Visualforce page, I get the error "Attempt to de-reference a null object" as soon as I preview it. Not sure what is going on or where to look for the error, but below is my  VF code and controller.

Visualforce Page
<apex:page controller="mySignatureController">
    <apex:pageBlock>
        <flow:interview name="Signature_Flow_Page" interview="{!mySignatureFlow}"
                        finishLocation="{!finishURL}"/>
    </apex:pageBlock>
    <apex:pageBlock>
        <apex:detail subject="{!AccountID}" relatedList="false" />
	</apex:pageBlock>
</apex:page>

Controller
public class mySignatureController{
    public Flow.Interview.Signature_Flow_Page mySignatureFlow { get; set;}
    
    public String getAccountID() {
        if (mySignatureFlow==null) return '';
        else return mySignatureFlow.AccountID;
    }
    public PageReference getfinishURL() {
        PageReference p = new PageReference('/' + mySignatureFlow.AccountID);
        p.setRedirect(true);
        return p;	
    }
}

Edwin VijayEdwin Vijay
You will have to look at the ERROR line# to narrow down. If the Preview page does not show the line# enable debug logs for yourself and find out the lie #.

My guess is that it is going to be line# 09. mySignatureFlow might be null and you are trying to acess an attribute of it. Replace it with this

PageReference p;
if (mySignatureFlow != null)
p = new PageReference('/' + mySignatureFlow.AccountID);
esle
p = new PageReference();

Visit forcetree.com for code samples and tips.
deux4everdeux4ever
It was line #9. I made the change you suggested, but had to add a couple of lines to fix errors and here is what I came up with.

public class mySignatureController{
    public Flow.Interview.Signature_Flow_Page mySignatureFlow { get; set;}
    
    public String getAccountID() {
        if (mySignatureFlow==null) return '';
        else return mySignatureFlow.AccountID;
    }
    public PageReference getfinishURL() {
		PageReference p;
        if (mySignatureFlow != null)
            p = new PageReference('/' + mySignatureFlow.AccountID);
        else
            p = new PageReference('home/home.jsp');
            p.setRedirect(true);
            return p;
    }
}