+ Start a Discussion
Karleen MendozaKarleen Mendoza 

Launch screen flow when task closed

Hi all, I'd like to create a screen flow that asks users a few questions and then this would update the related opportunity. I'd like this screen flow to trigger when a task related to the opportunity is closed. How do I pass through the related opportunity ID?
Alain CabonAlain Cabon
Hi,

Only autolaunched flows can be triggered on data changes and an autolaunched flow have no user interface context to display a page. 

If you are in Classics, there is just the URL hack using retURL for a redirection from a standard record edit layout at the save to a VFP that will launch the flow with your screen.  The URL hack only works in Classics.


1) Override the Edit button of Task with a Visualforce page that will just do the redirection to the standard edition of a task with &retURL=/apex/myFlow?id=

VFP for the override of the button "Edit" task
<apex:page standardcontroller="Task" extensions="redirectTask" action="{!redirect}">
</apex:page>
Simplified controller:
public Class RedirectTask {
    private task t {get;set;}
    public RedirectOppt(ApexPages.StandardController controller){
        t = (Task)controller.getRecord();
        t = [select id,whatid from task where id = :t.id];
    }
    public pagereference Redirect()
    {      
        String hostname = ApexPages.currentPage().getHeaders().get('Host'); 
        String taskURL2 = 'https://'+hostname+'/'+ t.Id +'/e?nooverride=1&retURL=/apex/CallFlow?id='+ t.whatid;
        pagereference pageref = new pagereference(taskURL2);
        pageref.setredirect(true);
        return pageref;
    }    
}

2) When you save the task, /apex/CallFlow?id='+ t.whatid (retURL) will be called automatically

CallFlow is VFP embedding the flow interview.

Minimal code without passing the id:
<apex:page>
<flow:interview name="Flow_Oppt_Id"/>
</apex:page>

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_flows_adding.htm

Here’s an example of a custom controller that sets the values of flow variables in a constructor:

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_flows_advanced.htm

This trick has been over-used because that doesn't work anymore with Lightning so that will have a big problem when you will want to migrate to Lex.
Alain CabonAlain Cabon
Only autolaunched flows can be triggered on data changes and an autolaunched flow has no user interface context to display a page. 
This trick has been over-used because that doesn't work anymore with Lightning so you will have a big problem when you want to migrate to Lex.
Karleen MendozaKarleen Mendoza
Thanks Alain. I appreciate it the advice. I'll look into this. I might just end up doing a workaround with record types, page layouts and validation rules to create the screen. 
Alain CabonAlain Cabon
Hi Karleen,

If you have a workaround without an URL hack (even the name is terrible), you will achieve peace of mind for the future. 

This URL hacks may be tempting (only known alternative in Classics only) but they are dangerous.