function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
John Smith 266John Smith 266 

Unable to instantiate a flow? page redirection error

I'm trying to set the finish location of a flow to the record created in that flow. I've tried setting up the controller a million different ways, but I keep getting an invalid page redirection error when the flow is finished.
 
It seems like, for some reason, my flow is not being instantiated as "theFlow". If I set the page reference to ('/' + 'home/home.jsp') or to a specific opp ID, then the finish location works fine. But any flow variable or anything referenced by theFlow.XXX fails.
 
Debug logs seem to indicate that theFlow is always null. And, if I include interview="{!theFlow}" in the visualforce page, it fails with an internal server error. All flow variables are set to input/output and there is a confirmation screen after the record create.
 
I have no idea what I might be missing. If the apex looks fine, what other user/org/security settings should I double check?
 
public class MemberPaymentFinishController2 {
    public Flow.Interview.Manual_Membership_Payment theFlow {get; set;}
    public String getFinishURL() {
        String FinishURL;
        if (theFlow==null) return '';
        else return theFlow.varOppID; }
   public PageReference getFinishPage(){
      PageReference p = new PageReference('/' + getFinishURL());
      return p; }
}
 
Here is the visualforce page code. It's being called by a custom tab if that matters. Also, all this is being done in my recently refreshed sandbox.
 
<apex:page Controller="MemberPaymentFinishController2" >
<flow:interview name="Manual_Membership_Payment" finishlocation="{!FinishPage}" />
</apex:page>
NagendraNagendra (Salesforce Developers) 
Hi John,

Please find the solution below suggested from the stack exchange community for the above issue.

Note that as I was tweaking an existing flow and VF page, my flow interview is quickCreateFlow, and the flow variable I'm using is called vaNewCreatedContactId.

Apex Class:
public class quickCreateContactController {

    public String myNewId { get; set; } //not needed, forgot to remove
    public Flow.Interview.Quick_Create_Contact quickCreateFlow { get; set; }

public String getFinishURL() {
        String FinishURL;
        if (quickCreateFlow != null) {
          FinishURL = quickCreateFlow.vaNewCreatedContactId;
          return FinishURL;
        }
        else return 'home/home.jsp';
        }

   public PageReference getFinishPage(){
      PageReference p = new PageReference('/' + getFinishURL());
      return p; 
      }
}
Visualforce Page:
<apex:page controller="quickCreateContactController">
    <div id="flow">    
        <flow:interview name="Quick_Create_Contact" interview="{!quickCreateFlow}" finishLocation="{!FinishPage}">
    </flow:interview>
    </div>    
</apex:page>

I believe that the issue you are encountering may be because theFlow.varOppID is null until it gets a value when the flow creates the record, so you are returning null when the method is supposed to return a string. When I was trying to run the flow when setup as you had it, I would get the following error:

Argument 1 cannot be null:

So I'm returning 'home/home.jsp' in the else branch when the flow is null, and I'm returning the FinishURL string in the getFinishURL method, instead of returning the flow Variable, which is null. My guess is that the VF page tries to set the finish location when it launches the flow and updates it on each screen. My guess is based on this SFSE post(http://salesforce.stackexchange.com/questions/96127/making-the-finishlocation-of-a-flow-as-the-newly-created-record) which indicates you need a screen after the record is created, as:

This screen causes a refresh of the visual force page which will then give the finishLocation access to the variable.

Please mark this as solved so that it gets removed from the unanswered queue which results in helping others who are encountering similar issue.

Regards,
Nagendra.

 
John Smith 266John Smith 266
As I commented on Stack Exchange, unfortunately, this did not solve the problem. I still get an internal server error when implementing this suggested code.