3

enter image description hereflow used : enter image description hereI have a flow which is having a variable (I/O) .I am using this variable in a flow and a controller. The flow needs to redirect the user to the particular record when the flow ends. Things doesn't go well when we run the flow on first attempt it get redirect to start point when flow ends how ever when we click next again and redo the steps it results in redirecting successfully.

VF Page:

<apex:page controller="ContactSimple"> <br>
<flow:interview name="Survey_customers" interview="{!myflow}" finishLocation="{!Router}"> <br>
</flow:interview><br> 
</apex:page><br>
<br>
Controller:
<br>public class ContactSimple {public Flow.Interview.Survey_customers myflow {get;set;}<br>public String firstName;public String test{get;set;}public String getFirstName()<br> {if(myflow==null) return 'na';else {return myflow.createdid;}}<br>public pagereference getRouter(){<br>    PageReference p  = new PageReference('/'+getFirstName());       p.setRedirect(true);    return p;}}
  • 2
    Hey, try highlighting your code and hitting the {} button next time. It works wonders. – Adrian Larson Feb 23 '16 at 19:11
3

Do you have a Screen element AFTER the record ID you are using is created? Your class looks to be spot on... it matches what I have on my blog post for this issue, however you need to make sure the variable has time to set before it can be used.

---EDIT---

I've gone back to square one and done the code with your variable. Just tested it and it should work for you with just copying and pasting it into your code. I have a feeling that with all the changes there was something small missing, and the way your code was formatted was hard to read (use the {} in the editor to format it).

Visualforce Page:

<apex:page controller="ContactSimple">
<flow:interview name="Survey_customers" interview="{!myflow}" finishLocation="{!NewRecord}"> 
</flow:interview>

Controller:

public with sharing class ContactSimple {

public ID getNewId = System.currentPagereference().getParameters().get('newid');
public Flow.Interview.Survey_customers myflow{get;set;}
public String getTheNewId(){ return getNewId; }
public ID returnId = getNewId;

public PageReference getNewRecord(){

    if(myflow != null) returnId = myflow.createdid;
    PageReference send = new PageReference('/' + returnId);
    send.setRedirect(true); 
    return send;

 }
}
| improve this answer | |
  • Yes, I do have the screen. I can post the flow if you need. Thanx David – cloudy-ritz Feb 23 '16 at 20:28
  • What is your variable that you're trying to redirect with? Right now looking at the code it does look like you might have the wrong variable going through. Why are you doing getFirstName? Don't you want to pass it through to a Record ID? – David Litton Feb 23 '16 at 21:03
  • My variable is createdid , I have updated the code using yours and still it didn't work , public with sharing class ContactSimple { public ID getNewId = System.currentPagereference().getParameters().get('newid'); public Flow.Interview.Survey_customers myflow {get;set;} public String getTheNewId() { return getNewId; } public ID returnId = getNewId; public PageReference getRouter(){ if(myflow != null) returnId = myflow.createdid; PageReference send = new PageReference('/' + returnId); send.setRedirect(true); return send; } } – cloudy-ritz Feb 23 '16 at 21:09
  • Is your variable setup to be OUTPUT? (or input and output) – David Litton Feb 23 '16 at 21:37
  • Its input and output – cloudy-ritz Feb 23 '16 at 21:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.