I have created a visual flow in Salesforce that automatically creates an opportunity, contact, opportunitycontactrole, and a custom object. The only trouble I am having is creating a Custom button to put on my Account page that returns the user (once they have clicked "finish" on the flow) to the opportunity that has been created from the flow. I have tried this:
/flow/Create_Opportunity?AccountID2={!Account.Id}&retURL={!Opportunity.Id}
and it just sends me back to the home screen in Salesforce.
Does anyone have any suggestions on how I can return the user back to the newly created opportunity from the flow?
Thanks!
Edit: 9/17/2014
Apex Class:
public class FlowFinishLocationController
{
public FlowFinishLocationController(ApexPages.StandardController controller) {
}
public Flow.Interview.FSE_Lead_Flow flow { get; set; }
public Opportunity opp {get;set;}
public PageReference finishLocation
{
get
{
flow.getVariableValue('Opportunity_Name_Field');
PageReference oppPage = new ApexPages.StandardController(opp).view();
return oppPage;
}
set;
}
}
Visualforce Page (I have the standard controller set to Account since I need to click on the link on the account page)
<apex:page standardcontroller="Account" extensions="FlowFinishLocationController">
<flow:interview name="FSE_Lead_Flow" interview="{!flow}" finishLocation="{!finishLocation}" />
</apex:page>
Attribution to: NewbieDeveloper27
Possible Suggestion/Solution #1
You can do this if you embed the flow in a VF page using the <flow:interview>
component and use the finishLocation parameter to define the URL (in this case the link to the newly created opportunity).
Since the URL will be dynamic, you'll also have to define a controller class that accepts the opportunity ID from the flow and uses it to generate the dynamic URL.
Attribution to: RohanC
Possible Suggestion/Solution #2
To do this you'll need to create a simple Visualforce page and a controller.
The page will use a flow:interview
component which you can bind to a Flow.Interview
attribute in your controller using the interview
attribute and a PageReference
attribute using the finishLocation
attribute.
Your PageReference
attribute in your controller can generate the PageReference
using your Flow.Interview
reference and getVariableValue(String)
which will pull the value from an Output value in your Flow.
The whole thing looks something like this:
Page:
<apex:page controller="FlowFinishLocationController">
<flow:interview name="YourFlowName" interview="{!flow}" finishLocation="{!finishLocation}" />
</apex:page>
Controller:
public class FlowFinishLocationController
{
public Flow.Interview.YourFlowName flow { get; set; }
public PageReference finishLocation
{
get
{
// Get your Id using flow.getVariableValue('Your Output Variable Name');
// Construct your PageReference manually using the Id or ApexPages.StandardController(SObject).view()
// Return your PageReference
}
set;
}
}
There is a little bit of information in the documentation, but it doesn't go into detail about pulling variables from your Flow to create the PageReference
.
Set
finishLocation
with a ControllerYou can set
finishLocation
in a few ways with a custom controller.This sample controller configures a flow’s finish behavior in three different ways. *
getPageA
instantiates a new page reference by passing a string to define the location. *getPageB
returns a string that is treated like a PageReference. *getPageC
returns a string that gets translated into a PageReference.public class myFlowController { public PageReference getPageA() { return new PageReference('/300'); } public String getPageB() { return '/300'; } public String getPageC() { return '/apex/my_finish_page'; } }
Here’s a sample Visualforce page references that controller and sets the flow finish behavior to the first option.
<apex:page controller="myFlowController"> <h1>Congratulations!</h1> This is your new page. <flow:interview name="flowname" finishLocation="{!pageA}"/> </apex:page>
If you use a standard controller to display a record on the same page as the flow, users who click Finish start a new flow interview and see the first screen of the flow, without the record. This is because the
id
query string parameter isn’t preserved in the page URL. If needed, configure thefinishLocation
to route users back to the record.
Attribution to: Alex Tennant
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/31101