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
Cory CowgillCory Cowgill 

Visual Flow inside Visualforce Page with Apex Controller - Lag in displaying values

I have a curious case where I have a Visual Flow embedded in a Visualforce Page. This works fine.

 

I have a few variables in the Flow which are exposed to the Visualforce Page (For example, contact Name, Phone, and Email) which I want to display during the entire Flow process.This works fine except one problem:

 

The variables aren't displayed when they are set in the Flow. I have to go to an additional screen by clicking Next or Previous to get the values back in the Visualforce Page when they have already been set in the Flow.

 

Anyone seen this similar type behavior? It's probably something super simple but I just don't see it at the moment.

Best Answer chosen by Admin (Salesforce Developers) 
Chris JohnChris John

Here's a good example on how to display flow variables within a Visualforce page:

 

http://www.salesforce.com/us/developer/docs/pages/index_Left.htm#StartTopic=Content/pages_flows_advanced.htm

 

How are you setting variables in the flow?

 

I've put some sample code below for a Flow that just searches for a Contact by email and displays the FirstName in the VF container, to see it changing as the variable changes in the Flow. In the flow, the variable for the firstname is assigned from a record search and stored in a variable 'vContactFirstName'. I changed the variable with an assignment element.

 

Hope that helps, we'd be happy to look at your controller and page code also.

 

-cj

 

/* Controller */
public class ContactSimple {

public Flow.Interview.ContactSearch myflow {get;set;}
public String firstName;

public String getFirstName() {

// Access flow variables as simple member variables with get/set methods
if(myflow==null) return 'na';
else return myflow.vContactFirstName;
}
}

 

<!-- VF Container Page -->
<apex:page Controller="ContactSimple" tabStyle="Contact" >
<flow:interview name="ContactSearch" interview="{!myflow}" reRender="nameSection" />
<apex:outputText id="nameSection" value="Contact First Name: {!firstName}"/>
</apex:page>

All Answers

Chris JohnChris John

Here's a good example on how to display flow variables within a Visualforce page:

 

http://www.salesforce.com/us/developer/docs/pages/index_Left.htm#StartTopic=Content/pages_flows_advanced.htm

 

How are you setting variables in the flow?

 

I've put some sample code below for a Flow that just searches for a Contact by email and displays the FirstName in the VF container, to see it changing as the variable changes in the Flow. In the flow, the variable for the firstname is assigned from a record search and stored in a variable 'vContactFirstName'. I changed the variable with an assignment element.

 

Hope that helps, we'd be happy to look at your controller and page code also.

 

-cj

 

/* Controller */
public class ContactSimple {

public Flow.Interview.ContactSearch myflow {get;set;}
public String firstName;

public String getFirstName() {

// Access flow variables as simple member variables with get/set methods
if(myflow==null) return 'na';
else return myflow.vContactFirstName;
}
}

 

<!-- VF Container Page -->
<apex:page Controller="ContactSimple" tabStyle="Contact" >
<flow:interview name="ContactSearch" interview="{!myflow}" reRender="nameSection" />
<apex:outputText id="nameSection" value="Contact First Name: {!firstName}"/>
</apex:page>

This was selected as the best answer
Cory CowgillCory Cowgill

Thanks for the information!

 

I am not using an Assignment Element, I am storing directly in variable from one of the screens dropdown choices that returns the list and puts the selected item in the variable.

 

Let me see if that is the difference.

 

Everything else is pretty much the same. Just seems to lag one screen behind. Weird!

Cory CowgillCory Cowgill

Thanks. I resolved it by comparing my code to yours. Looks like it was a typo IF statement in my controller that wasn't getting refired.

 

Thanks!

Chris JohnChris John

Great!

oodood

When I created new record  Lead or Opportunity by visual flow and then I want to get new Id to Visualforce page don't need finish page redirect to detail page.Have any idea?

goabhigogoabhigo

I am very curious to know the test class for this. Can you please share some tips? I too have a Flow which is embedded inside VF page, which has a controller method. I need to write test class for that controller..