+ Start a Discussion
sunnydalesunnydale 

Controlling Finish actions outside of a VFP

Is there a way to change the Finish button default on a VWF run from a custom button URL that's not referencing a VFP?  Basically I have a simple flow that starts with a button click from a detail page, which opens a new browser window and shows some data along with the standard VWF Finish button. 

 

What I'd like is for finish to close the window, not restart the workflow.

 

 

RichJRichJ

You could pass in a return URL (e.g retURL=URLFOR({!Lead.Id})), so that when the flow finishes in the new window it is redirected back to the detail page of your record, but this wont close the new window.

 

Salesforce recommend against this if you are using a link that opens the flow in the existing window because you will end up with a salesforce page with side bar and top panel within a salesforce window with side bar and top panel etc.

 

The other option is to create a visualforce page to display your flow. You could then have some javascript / jquery that 'rehooks' the Finish button event so that it closes the window. There is a finishLocation parameter that will redirect the page but it wont close the window.

BenjobobbyBenjobobby

I'm just starting with flows - they seem like pretty powerful tools for managing data quality and doing process checks. However, the finish behavior just baffles me - it seems intuitive that when you click "Finish", the window should close, or at least that there should be some (easy) way to configure this in the designer. What am I missing about the original intent for flows that Salesforce had? What is the use-case where you'd want to restart the flow from the beginning? (not to mention having lost the record context at that point). I don't get it.

 

We run our flows off a button on a detail page, as per the original post. We want the user to click the button, have the flow pop-up and guide them through a process, then they click "Finish" at the end and the pop-up flow closes and they're returned to the originating page. Might someone be able to provide a little more detail on how to effect this? Many thanks. -Ben

wahoobiewahoobie

I am with Benjobobby here in seeking a clean close method. I'll have to log something to Ideas if I can't find any leads for my newbiness.

Alex K.Alex K.

This is a little weird, however the method devised kind of makes sense. What you have to do is make a VisualForce page wrapper and call that wrapper (instead of the flow) when making a button.

 

Sounds confusing, but it's one line line of code.

 

Go to Develop -> Pages -> New

 

And create a new VisualForce page with following content:

 

<apex:page >
<flow:interview name="YourFlowName" finishLocation="{!URLFOR('/home/home.jsp')}"/>
</apex:page>

And of course "YourFlowName" above is the Unique Name of the flow (located on top right corner of the flow edit page). Set the finish location to wherever you like.

 

After that go to your object page and create a button that points to the URL of the VisualForce page.

 

One fun thing that isn't immediately obvious is that you can pass variables from your object to the flow by using the flow name variable in the URL string. Make sure the flow name variable isn't set to private and use the variable name in the button link URL like this:

 

/apex/VFPage?OppID={!Opportunity.Id}

 

Where "VFPage" is the name of the Visual Force page and "OppID" is the name of my flow variable. You can pass multiple variables with "&" 

 

 

 

 

 

nickboekanickboeka

thanks for the VF example.

 

But I have a twist on the question, how do I do both?

 

In other words, I am using a button on the oppy page, to pass variables in from the record and set the variable for the record that I want to update.  But I also want to execute this VF example, so it closes the popup when the user hits the Finish button (it will also update the records that they've filled in during the Flow).

 

I can't seem to figure out how to implement both solutions at the same time, since the button only allows me to select URL or VF.

 

 

Alex K.Alex K.

Closing when done.

 

I don't remember if I found this somewhere or figured it out, because it's not in the documentation - but it works great. One method to close the flow page when "finish" is clicked is to first create a separate VisualForce page called "closeWin" that does just that (using Javascipt) as so:

 

<apex:page >
<script language="JavaScript">
close();
</script>
</apex:page>

 Then set that page as the "finish location" in the flow wrapper page  (mentioned in earlier post above), like this:

 

<apex:page showHeader="false" sidebar="false">
<flow:interview name="YourFlowName" finishLocation="closeWin"/>
</apex:page>

 As soon as the user clicks finish, it goes away.

 

Be sure and set the "Window Open Properties" behavior on the button you set up to "Display in a new window"  - or they'll close their only window. I open the flow window in top left and set it to 350 x 750 pixels and it's worked pretty well in most cases. 

 

 

james.molloyjames.molloy
Sorry to revive an ancient thread but I found a great solution you can use for all your flows - and you never marked this question as solved.

There's a simple 2-step solution that can then be used for all Flows without needing a custom VFP per Interview.

Step 1: Create a VisualForce Page called forceclose
<apex:page showChat="false" showHeader="false" sidebar="false" applyBodyTag="false" applyHtmlTag="false">
<html>
    <head>
        <title>ESCAPE</title>
        <script>
            function closeWindow() {
                window.open('','_parent','');
                window.close();
            }
        </script>       
    </head>
    <body onload="closeWindow()">
       
    </body>
</html>
</apex:page>

Step 2: Append the follwing to the end of your interview URLs (good for buttons or links)
&retURL=/apex/forceclose
 

Voila! Hitting the finish button will call this VF page that calls the window.close() function and this will dismiss the flow's window/tab.
RickSRickS
I can confirm that James.molloy's solution works perfectly.
Peanutman21Peanutman21
The solution James Molloy has above works like a charm. Thanks James!
Codi Kodama 9Codi Kodama 9
 I was able to achieve the goal by adding the following details to the custom button that launches my Visual Workflow:

  1. Append &retURL={Object.Id} to the URL on my Custom Button
  2. Change the Behavior to "Display in existing window without sidebar or header"
After clicking the button the Visual Workflow takes up the entire screen and the User navigates through the flow. After clicking "Finish" the Visual Workflow window closes and returns to the record and is refreshed.
JShaffJShaff
Hi.  Glad I found this post and i am able to accomplish closing the flow using the examples above for my Custom Link URL.  However, I am wondering if there is any way I can accomplish these 2 things using the URL that launches the flow:
Upon Finish:
1. Close the flow and,
2. Direct User to the specific record they created/udpdated during the flow. 

Right now, my URL looks like this where I"m passing a Variable to the Account record:
/flow/Special_Event_Wizard?varaccID={!Account.Id}&retURL=/apex/forceclose

The force Close works but just leaves me on a blank page with the Header and Sidebar.  Ideally, I want it to go to the record that was  created in the flow.

 
james.molloyjames.molloy
Hi JShaff, looks like you may want to consider using a <flow:interview> (https://www.salesforce.com/us/developer/docs/pages/Content/pages_flows_advanced.htm)in Visualforce, then you can control where you go based on flow outcomes (you can use PageReference (https://www.salesforce.com/us/developer/docs/pages/Content/pages_quick_start_controller_navigation_methods.htm)in the controller to handle navigating when the form completes)
 
JShaffJShaff
Thanks very much James.  Since I posted, I have made some strides in this (I am not an Apex developer so have to do a lot of reading).

I have it behaving closer to what I want with one exception now.  The parameter I'm passing is in the APEX Page is not correctly populating the lookup field in the record the Flow is creating.  This was working correclty when I was launching the flow from a Custom Link URL but when I try to launch the Flow from a VF Page, I see the ID of the variable in the URL above but it isn't passing into the lookup field.  The variable in the  Flow Designer is set to Input/Output and hasn't changed since I was originally using a custom link URL. 

VF Page code:
The varaccID param is what I have defined in the Flow Designer and it is supposed to accept the AccountID.  Again, I can see it in the URL when I launch the Flow from the VF link but just isn't populating the Variable in my flow correctly

<apex:page standardController="Account" recordSetVar="Accounts" extensions="Account_Controller"> <flow:interview name="Special_Event_Wizard" finishLocation="{!URLFOR('/home/home.jsp')}"> <apex:param name="varaccID" value="{!Account.id}"/> </flow:interview> </apex:page>

No worries if you aren't sure.  I will somehow figure this out.

Thanks Again.

 
james.molloyjames.molloy
To pass custom variables in you need to create a function to handle that in your controller.
There's an example of this here (https://www.salesforce.com/us/developer/docs/pages/Content/pages_flows_advanced.htm) (about 3 code-snippets down):
public class ModemTroubleShootingCustomSetVariables {
    public Flow.Interview.ModemTroubleShooting myflow { get; set; }
 
    public ModemTroubleShootingCustomSetVariables() {
        Map<String, Object> myMap = new Map<String, Object>();
        myMap.put('vaCaseNumber','123456');
        myflow = new Flow.Interview.ModemTroubleShooting(myMap);
    }
 
    public String caseNumber { set; }
    public String getCaseNumber() {
        return myflow.vaCaseNumber;
    }
}
Cheers, and happy coding!
 
Ruth Isabel TuraewRuth Isabel Turaew
Unfortunately, I'm getting an error saying the URL no longer exists when I click on my Custom Button that launches a flow. First I tried James Molloy's suggestion of creating a VF page called forceclose and then adding &retURL=/apex/forceclose to the end of the URL of the flow url. Next, I tried CodiKodama9's suggestion and I also received the same error. I know this is an old thread, so I'm wondering if may the retURL no longer works? I'd appreciate any help you can give me. 
Peanutman21Peanutman21
Hey Ruth!
Here is the syntax for the URL behind my custom button:
/flow/Website_Request_Center?AccountId={!Account.Id}&AccountName={!Account.Name}&ARNumber={!Account.AR_Number__c}&retURL=/apex/ForceClose
Below is the code behind my the ForceClose VF Page:
​<apex:page showChat="false" showHeader="false" sidebar="false" applyBodyTag="false" applyHtmlTag="false"> <html> <head> <title>ESCAPE</title> <script> function closeWindow() { window.open('','_parent',''); window.close(); } </script> </head> <body onload="closeWindow()"> </body> </html> </apex:page>
Hope this helps!
Megan D MoodyMegan D Moody
I am having the same problem Ruth was having. My ForceClose VF page is exactly as you put above, Peanutman21. My button launches the flow just fine without the &retURL=/apex/ForceClose at the end, but I get the URL No Longer Exists error if I try to add it on. Any ideas on how to fix this? I got this solution working at my former company, so I know it works. Just can't figure out why I'm getting this bug. 
Eric_SchubertEric_Schubert
Hey Megan!

I know this is a long shot, but when you go to Setup > Security Controls > Session Settings > Clickjack Protection, is anything checked there? I am wondering if it has something to do with clickjack protection.

Eric
 
Steve Jones 34Steve Jones 34
Peanutman21's code for the ForceClose vf page worked perfectly for me. I am calling it from another vf page that drives the visual workflow by using the URLFOR expression in the finishLocation specification as per the example below:

<flow:interview name="MyFlow" finishLocation="{!URLFOR('/apex/ForceClose')}">

I thought Eric's comment about clickjack protection may have been right about the reason for it not working in Megan's case - however I enabled clickjack protection for visualforce pages and it still worked.

 
Sonya Dhand 3Sonya Dhand 3
Hi 

I have this nearly working. So thanks @James.Molloy  My custom button is calling my flow and then closing the pop up window by calling the vf page as above. However now I need the page to refresh so the new data inputted by the flow takes effect.

I guess I need this somewhere but unsure where?  document.location.reload(true)  In the VF page code somewhere?

Any ideas?
Sonya Dhand 3Sonya Dhand 3
Hi 

I am trying to edit the vf page to reload when the windo closes but is returning to the home page and not to the parent window.  Any ideas?
 
<html>
    <head>
        <title>ESCAPE</title>
        <script>
            function closeWindow() {
                window.open('','_parent','');
                window.opener.location.href="/{!$CurrentPage.parameters.id}""
                window.close();
            }
        </script>       
    </head>
    <body onload="closeWindow()">
       
    </body>
</html>
</apex:page>



 
Trevor HeywoodTrevor Heywood
Is there any news on the refresh of the parent page? Apart from this everything is working well.
Doug Yeager 8Doug Yeager 8
My problem is that the ForceClose VF page stopped working when I changed the UI style to Lightning - anybody else notice this?
Heather Simoneau 1Heather Simoneau 1
For those struggling with James.Molloy's solution, here are the syntax changes I made so that it would work in my custom link:
/flow/New_Service_Request?retURL=apex/flowforceclose

Great solution, James!