You need to sign in to do that
Don't have an account?
Josh Davis 13
How to access workflow variable in apex to set a page reference for finishlocation
I'm new to VisualForce, so likely missing something simple. I have a simple flow that looks up a contact, and if it finds a match writes the matching contact.id to a text variable. I know this works because in a later step I refer to the variable to update the existing record. But I want this workflow to go to the lookup record when it's done. It sounds like the best way to do that is setting the finishlocation to a page reference that pulls the variable from the workflow. But that page reference keeps coming up null--so the variable value isn't getting pulled into the controller.
Here's my page. "HES_signup_test" is the name of the otherwise working workflow:
<apex:page controller="HESFlowToSchedule">
<flow:interview name="HES_signup_test" interview="{!myflow}" finishlocation="{!ContactPage}">
</flow:interview>
</apex:page>
Here's my controller, copied from an example at https://developer.salesforce.com/forums/?id=906F0000000QtIxIAK. "PassToSO" is the flow variable name.
public class HESFlowToSchedule {
public Flow.Interview.HES_signup_test myflow {get; set;}
public PageReference ContactPage {
get {
PageReference pageRef = new PageReference('/' + flowContactId );
pageRef.setRedirect(true);
return pageRef;
}
set { ContactPage = value; }
}
public String flowContactId {
get {
String strTemp = '';
if(myflow != null) {
strTemp = myflow.PassToSO; //also tried string.valueOf(myflow.getVariableValue('PassToSO'));
}
return strTemp;
}
set { flowContactId = value; }
}
}
In this example, logs show StrTemp ends up null, even though PassToSO is successfully used in the workflow. PassToSO is set for Input and Output use.
I also tried this second construction, from https://developer.salesforce.com/docs/atlas.en-us.208.0.pages.meta/pages/pages_flows_advanced.htm:
public class HESFlowToSchedule {
public Flow.Interview.HES_signup_test myflow {get; set;}
public PageReference getcontactPage() {
String apexPassToSO;
if (myFlow==null) { return new PageReference('/0030q000001xgYH');}
else {
apexPassToSO = (String) myFlow.getVariableValue('PassToSO');
if (apexPassToSO==null) {return new PageReference('/0033700000SEGA8');}
else {
return new PageReference('/' + apexPassToSO);
}
}
}
and it pulled a null value.
Then I tried this, from https://help.salesforce.com/articleView?id=pages_flows_getting_values.htm&language=en_US&type=0, with same failure.
public class GetPassToSO {
public Flow.Interview.HES_signup_test myflow { get; set; }
public String apexPassToSO;
public String getApexPassToSO() {
return myflow.PassToSO;
}
}
What am I missing? Thanks for any clues!
Here's my page. "HES_signup_test" is the name of the otherwise working workflow:
<apex:page controller="HESFlowToSchedule">
<flow:interview name="HES_signup_test" interview="{!myflow}" finishlocation="{!ContactPage}">
</flow:interview>
</apex:page>
Here's my controller, copied from an example at https://developer.salesforce.com/forums/?id=906F0000000QtIxIAK. "PassToSO" is the flow variable name.
public class HESFlowToSchedule {
public Flow.Interview.HES_signup_test myflow {get; set;}
public PageReference ContactPage {
get {
PageReference pageRef = new PageReference('/' + flowContactId );
pageRef.setRedirect(true);
return pageRef;
}
set { ContactPage = value; }
}
public String flowContactId {
get {
String strTemp = '';
if(myflow != null) {
strTemp = myflow.PassToSO; //also tried string.valueOf(myflow.getVariableValue('PassToSO'));
}
return strTemp;
}
set { flowContactId = value; }
}
}
In this example, logs show StrTemp ends up null, even though PassToSO is successfully used in the workflow. PassToSO is set for Input and Output use.
I also tried this second construction, from https://developer.salesforce.com/docs/atlas.en-us.208.0.pages.meta/pages/pages_flows_advanced.htm:
public class HESFlowToSchedule {
public Flow.Interview.HES_signup_test myflow {get; set;}
public PageReference getcontactPage() {
String apexPassToSO;
if (myFlow==null) { return new PageReference('/0030q000001xgYH');}
else {
apexPassToSO = (String) myFlow.getVariableValue('PassToSO');
if (apexPassToSO==null) {return new PageReference('/0033700000SEGA8');}
else {
return new PageReference('/' + apexPassToSO);
}
}
}
and it pulled a null value.
Then I tried this, from https://help.salesforce.com/articleView?id=pages_flows_getting_values.htm&language=en_US&type=0, with same failure.
public class GetPassToSO {
public Flow.Interview.HES_signup_test myflow { get; set; }
public String apexPassToSO;
public String getApexPassToSO() {
return myflow.PassToSO;
}
}
What am I missing? Thanks for any clues!