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
TensorTenorTensorTenor 

Flow & VisualForce error - Attempt to de-reference a null object

I have what I thought would work as a flow embedded in a visualforce page with a custom controller, but I am running into a bit of an issue at runtime. Here is the code for the VF page:

<apex:page controller="TestimonialLookupbyAreaFlowController">
  <flow:interview name="Testimonial_Lookup_by_Area" interview="{!TLBAFlow}" finishLocation="{!ReportParam}" />
</apex:page>

 And here is the code for the controller:

public class TestimonialLookupbyAreaFlowController{
    public Flow.Interview.Testimonial_Lookup_by_Area TLBAFlow{get; set;}
    
    public String getZip(){
    	if(TLBAFlow==null) return '';
        else return TLBAFlow.Zip_to_Pass;
    }
    
    public pageReference getReportParam(){
    	PageReference p = new PageReference('/00OQ0000000GWwx?pv0=' + getZip());
        return p;
    }
}

 The finishLocation is a report that I am passing a variable to from the flow. I can get to the report with no problem, but whatever is in the variable doesn't matter as the parameter is always null. I removed the if statement from the getZip() method and I believe I have figured out what is going on but not why. After removing the if statement I got an error about attempting to de-reference a null object when I attempted to open the VF page. So I am assuming that as the code stands currently, every time getZip() is called, the comparison 'TBLAFlow == null' is returning true, thus the parameter is always a null string. Does anyone have any idea why the flow object is null here?

Best Answer chosen by Admin (Salesforce Developers) 
DarrellDDarrellD

Yes, it's noted here somewhere that a Flow has to end on a screen for it to pass on the variable elements. It's not actually in the docs though since it's a (quirk/bug) that this happens. Actually, I think it was my post from early in the year that uncovered this. We have generic "This wizard has ended" screens for this purpose. Glad you found the error!

 

Here's the original post with same finding:

http://boards.developerforce.com/t5/Visual-Workflow/Flow-variables-not-passing-back-to-VF-Controller-Extension/td-p/503865

All Answers

DarrellDDarrellD

Is your return variable labeled as Input/Output...or at least Output in your Flow? That would be needed for it to return a value.

TensorTenorTensorTenor

Yes, the variable in the flow is set to output.

DarrellDDarrellD

What type of variable is it? Have you seen the runtime behavior changes for null vs. empty strings? We have a VF page that does the exact same thing you are trying to do, however we have encountered a separate Summer 13 bug so we can't get to the return page stage yet so I haven't been able to confirm if we need to change the "var == null" to "empty string" or something else, but see if this sheds any light on it.

 

http://help.salesforce.com/apex/HTViewSolution?id=000181397&language=en_US

TensorTenorTensorTenor

I have absolutely no idea why this worked, but I seem to have accidently stumbled on a solution in case anyone else is having the same problem. I added a finish screen to my flow asking the user if their input was correct but displaying the variable value rather than the input field so that I could test to see if the assignment was working properly. It was and now the variable value is being passed to the URL properly. The only change I made was adding a screen after the assignment element in the flow. Is it standard practice to not end a flow with an assignment element?

DarrellDDarrellD

Yes, it's noted here somewhere that a Flow has to end on a screen for it to pass on the variable elements. It's not actually in the docs though since it's a (quirk/bug) that this happens. Actually, I think it was my post from early in the year that uncovered this. We have generic "This wizard has ended" screens for this purpose. Glad you found the error!

 

Here's the original post with same finding:

http://boards.developerforce.com/t5/Visual-Workflow/Flow-variables-not-passing-back-to-VF-Controller-Extension/td-p/503865

This was selected as the best answer
Eddie_TractionEddie_Traction

This is a major bug that needs to be addressed.

 

For some of the flows I've built you can set the finishlocation by passing it into the page and then using the Apexpages.currentPage().getParameters()