Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.