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
Salesforce WizardSalesforce Wizard 

Controller Flow null despite specifying Interview in visualforce page

I'm trying to get a value of a flow variable. I'm following this: http://www.salesforce.com/us/developer/docs/pages/Content/pages_flows_getting_values.htm

In the doc it specifies I need a vairable for my flow in my controller and specify that variable on the visualforce page with interview="{FlowVariable" 

I've done this, but when I launch the flow from the visualforce page my flow variable is null.

What am I missing? From what I can tell I got everything set right and it should work.

 

<apex:page standardcontroller="Opportunity" extensions="Closed_Won_Pathway_ext" >
<flow:interview name="FlowName" finishLocation="{!IAmFinish}" interview="{!myFlow}" >
    	<apex:param name="varOppID" value="{!Opportunity.id}"></apex:param>       
    </flow:interview>
</apex:page>
and the controller
public class Closed_Won_Pathway_ext {
    private final Opportunity opty; //final opportunity where the flow is started
    public string RecordID;
    
    public flow.Interview.Close_Won_This_Opp myFlow {get;set;}
    
    //constructed
    public Closed_Won_Pathway_ext(ApexPages.standardController con){
        this.opty = (Opportunity)con.getRecord();       
    }
    
    //get the contractid from the flow
    public string getRecordId(){        
        system.debug('myflow: ' + myFlow); //This is Null       
        system.debug(myFlow.varContractID); //This is a null pointer error
        return myFlow.varContractID;
    }
    
    //finish location
    public pagereference getIAmFinish(){
        PageReference thePage = Page.Celebrate;        
        thePage.getParameters().put('id',getRecordId());
        
        return thePage;
    }

}



Best Answer chosen by Salesforce Wizard
Salesforce WizardSalesforce Wizard
Problem solved!

So the code is actually correct.

What's happening is the flow has 2 pathways. The first pathway there's a screen, but no finish location. This is fine - we don't want the user to click finish.

The second pathway which is a "success" there's no final screen for the user to click "Finish" so it sort of acts like a headless workflow.

Because of this, my page methods are being called twice - but by the time it's being called a second time with the CORRECT redirect... the flow's redirect has already been set...as NULL. So it doesn't get redirected successfully.

Adding a final screen that forces the user to click "Finish" fixes the problem

All Answers

Grazitti TeamGrazitti Team
Be sure enough that you have defined case sensitive variables in the flow that you are using .
Also ensure that variables are of type input and output.

let us know if you have any question .
please don't Forget to Mark this as your best answer if it works fine for you

Regards,
Grazitti Team
Web: www.grazitti.com

Salesforce WizardSalesforce Wizard
Thanks for the answer.

Variables are already set as input and output and the case sensitivity is correct.

Any other suggestions?

Salesforce WizardSalesforce Wizard
I should add, if it was an issue with the case sensitivity, shouldn't I still see something other than null from system.debug('myflow: ' + myFlow); in getRecordID() method?
Salesforce WizardSalesforce Wizard
Not sure why it would make a difference, but could it be it's because I'm using a standardController with an Extension instead of just a custom controller?
Salesforce WizardSalesforce Wizard
And just to clarify, I had a bad Copy and paste in the original post:

<apex:page standardcontroller="Opportunity" extensions="Closed_Won_Pathway_ext" >
    
    <flow:interview name="Close_Won_This_Opp" finishLocation="{!IAmFinish}" interview="{!myFlow}" >
    	<apex:param name="varOppID" value="{!Opportunity.id}"></apex:param>
        <!-- <apex:param name="varContractID" value="" assignTo="{!RecordID}" /> -->
    </flow:interview>
</apex:page>
So the flow name does line up correctly to the name of my flow.
Salesforce WizardSalesforce Wizard
Found some more information that may be helpful.

I added a whole bunch of debug logs. It appears that my PageReference method is being called twice. Once when I click the button to activate the flow and once again with the flow actually completes.

The second time, myFlow is not null and contains my varContractID from the flow as I expected. I added a bit of logic and according to my debug logs, my redirect has the correct page and ID from varContractID... but the page doesn't actually redirect.

if I hard code the variable for instead of pulling it from the flow... the redirect works just fine. 

Any ideas?
Salesforce WizardSalesforce Wizard
Problem solved!

So the code is actually correct.

What's happening is the flow has 2 pathways. The first pathway there's a screen, but no finish location. This is fine - we don't want the user to click finish.

The second pathway which is a "success" there's no final screen for the user to click "Finish" so it sort of acts like a headless workflow.

Because of this, my page methods are being called twice - but by the time it's being called a second time with the CORRECT redirect... the flow's redirect has already been set...as NULL. So it doesn't get redirected successfully.

Adding a final screen that forces the user to click "Finish" fixes the problem
This was selected as the best answer
Raju I 5Raju I 5
 System.NullPointerException: Attempt to de-reference a null object Error is in expression '{! search_now}' in component <apex:commandButton> in page accountsearch: External entry point<apex:page Controller="c7">
<!---<apex:page  contentType="c7">-->
 <apex:form >
 <apex:pageBlock title="My Search1">
 <apex:inputText value="{!keyword}"/>
 
 <apex:commandButton value="search" action="{! search_now}"/>  
 <apex:pageBlockTable value="{!results}" var="r">
  <apex:column value="{!r.NAME}"/>
  <apex:column value="{!r.TYPE}"/>
  <apex:column value="{!r.PHONE}"/>
 </apex:pageBlockTable>
 </apex:pageBlock>
 </apex:form>
</apex:page>
and apex

public class c7{

string keyword ;
List<account> results;
//public <account> results{get;set;}
public  string getkeyword()
{

Return Keyword;
}

Public List<account> getresults()
{

 return results;
 }
 
 //piblic  void setKeyword (string input)
 
  public void setkeyword (string input)
 {
  string keyword = input;
 }
 
 public pagereference search_now()
 {
 results=(list<account>)[FIND:keyword IN ALL FIELDS RETURNING account(NAME,PHONE)][0];
 return null;
 
 }
Tamar ErlichTamar Erlich
Hi Brian,

 I am running into this exact problem when trying to redirect my finish location to the new record created by the flow, however, adding a final flow screen is not a viable option for me since the client wants to be taken to the new record directly without having an extra click. Where you ever able to fins a solution that does not require that final screen?

 Thank you, Tamar.