1

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>
  • 1
    Is varOppID an output only or input/output in its settings in the flow? – Dave Humm Feb 15 '17 at 0:23
  • Please include your visualforce as well. – Christian Carter Feb 15 '17 at 3:16
0

I was able to get it working as follows.

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 which indicates you need a screen after the record is created, as:

this screen causes a refresh of the visualforce page which will then give the finishLocation access to the variable.

My explanation may or may not hold water - its definitely not my area of expertise, but I think if you follow this pattern it should work for you. I suppose its possible that you just need a screen after the record is created?

FWIW I used the pattern that the poster used in this SFSE post to set the finish location.

  • I still get an internal server error using the code you have outlined. The only difference at this point between my code and yours is the name of the flow... – John Smith Feb 21 '17 at 20:33
  • Can you hard code the finishURL variables value in the flow to see if that makes a difference? Maybe it's getting something it doesn't like? Try debug logs w profiling set to finest, that might give some clues. – gorav Feb 21 '17 at 20:54
  • 1
    I think at this point, I'm just calling it quits on the finish location. It drives me nuts that I can't figure it out, but I guess that's life sometimes :) For now, I've added a hyperlink to the opp record on the finish screen and that's a decent workaround for my purposes. Adding the following to a display text field worked great <a href="naXX.salesforce.com{!varOppID}">Click here to go to the payment record and print a paper receipt.</a> – John Smith Feb 22 '17 at 20:02
  • I typically go that route myself. Maybe someday we will just be able to set the finish location in the flow. – gorav Feb 22 '17 at 20:05
0

I was having similar issues, and found that using the getVariableValue method solved my problem. This worked:

public class createQuoteExtension {


    public Flow.Interview.New_Quote_Starting_point quoteFlow {get; set;}
    public Id quoteId;

    public createQuoteExtension(ApexPages.StandardController controller) {

    }

    public String getQuoteId() {

        if(quoteFlow != null) {
           system.debug('quoteFlow is not null'+ quoteFlow.getVariableValue('varNewQuoteId')); 
           return '/quoteitm/multilineitem.jsp?quoteId=' + quoteFlow.getVariableValue('varNewQuoteId'); 

        } else {
           system.debug('quoteFlow is null'); 

           return '/home/home.jsp'; 
        }
    }

    public PageReference getFinishPage() {
        PageReference p = new PageReference( getQuoteID() );

        p.setRedirect(true);

        return p;
    }


}`

This didn't work:

    public class createQuoteExtension {


    public Flow.Interview.New_Quote_Starting_point quoteFlow {get; set;}
    public Id quoteId;

    public createQuoteExtension(ApexPages.StandardController controller) {

    }

    public String getQuoteId() {

        if(quoteFlow != null) {
           system.debug('quoteFlow is not null'+ quoteFlow.getVariableValue('varNewQuoteId')); 
           return '/quoteitm/multilineitem.jsp?quoteId=' + quoteFlow.varNewQuoteId; 

        } else {
           system.debug('quoteFlow is null'); 

           return '/home/home.jsp'; 
        }
    }

    public PageReference getFinishPage() {
        PageReference p = new PageReference( getQuoteID() );

        p.setRedirect(true);

        return p;
    }


}

There is an example of it here: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_flows_advanced.htm

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.