Skip to content

Instantly share code, notes, and snippets.

@noeticpenguin
Last active August 29, 2015 14:00
Show Gist options
  • Save noeticpenguin/11047814 to your computer and use it in GitHub Desktop.
Save noeticpenguin/11047814 to your computer and use it in GitHub Desktop.
Universal Redirect controller for VF Based Pages.
<apex:page Controller="FlowRedirectController">
<flow:interview name="RedirectFlow" interview="{!redirectTo}" finishLocation="{!finishLocation}" >
<!-- This Parameter is *required!* -->
<apex:param name="StartFlow" value="YOUR_FLOW_NAME_HERE" />
<!--
Any Params you need to pass into your flow.
<apex:param name="CaseId" value="{!CaseId}"/>
-->
</flow:interview>
</apex:page>
Public class FlowRedirectController{
Public Flow.Interview.RedirectFlow redirectTo {get; set;}
public FlowRedirectController() {
Map<String, Object> forTestingPurposes = new Map<String, Object>();
forTestingPurposes.put('vFinishLocation','codefriar.wordpress.com/');
redirectTo = new Flow.Interview.RedirectFlow(forTestingPurposes);
}
Public PageReference getFinishLocation(){
String finishLocation;
if(redirectTo != null) {
finishLocation = (string) redirectTo.getVariableValue('vFinishLocation');
}
PageReference send = new PageReference('/' + finishLocation);
send.setRedirect(true);
return send;
}
}
@isTest
private class Test_FlowRedirectController{
static testmethod void SetVariablesTests() {
PageReference pageRef = Page.ExampleVFFlow;
Test.setCurrentPage(pageRef);
FlowRedirectController testCtrl = new FlowRedirectController();
System.assertEquals(testCtrl.getFinishLocation().getUrl(), '/codefriar.wordpress.com/');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment