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>
Best Answer
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.