Last active
August 29, 2015 14:00
-
-
Save noeticpenguin/11047814 to your computer and use it in GitHub Desktop.
Universal Redirect controller for VF Based Pages.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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