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
Haseeb Ahmad 9Haseeb Ahmad 9 

Need help lightning flow running with visualforce page not redirting back to opportunity

Hi,

I have an issue where flow works but now when I enter all the inputs screen components and click next and finish.

Instead of redirecting me back to the current opportunity page, I am staying on 1st screen component like the process is starting again.

here is my code do you do what is the problem in this:
 
<apex:page controller="EngageDealSupportButtonClass" lightningstylesheets="true">
    <apex:param name="opportunityId" value="{!$CurrentPage.parameters.opportunityId}"/>
    <html>
        <head>
            <apex:includeLightning />
        </head>
        <body class="slds-scope">
            <div id="flowContainer" />
            <script>
            var statusChange = function (event) {
                if(event.getParam("status") === "FINISHED") {
                    // Control what happens when the interview finishes
                    
                    var outputVariables = event.getParam("outputVariables");
                    var outputVar;
                    for(var i = 0; i < outputVariables.length; i++) {
                        outputVar = outputVariables[i];
                        if(outputVar.name === "redirect") {
                            var urlEvent = $A.get("e.force:navigateToSObject");
                            urlEvent.setParams({
                                "recordId": outputVar.value,
                                "isredirect": "true"
                            });
                            urlEvent.fire();
                        }
                    }
                }
            };
            $Lightning.use("c:lightflowApp", function() {
                // Create the flow component and set the onstatuschange attribute
                $Lightning.createComponent("lightning:flow", {"onstatuschange":statusChange},
                                           "flowContainer",
                                           function (component) {
                                               // Set the input variables
                                               var inputVariables = [
                                                   {
                                                       name : 'opportunityId',
                                                       type : 'SObject',
                                                       value : component.get ("v.recordId")
                                                   }
                                               ];
                                               
                                               // Start an interview in the flowContainer div, and 
                                               // initializes the input variables.
                                               component.startFlow("pservicerequest", inputVariables);
                                           }
                                          );
            });
            </script>
        </body>
    </html>
</apex:page>
any thoughts on how can I resolve this? thank you.
AnudeepAnudeep (Salesforce Developers) 
Can you try performing the redirect using window.location as suggested in this post?

 
Haseeb Ahmad 9Haseeb Ahmad 9
Hi Anudeep,

Thank you for your reply so I need to create an Aura component for this to work? 
Haseeb Ahmad 9Haseeb Ahmad 9
Hi Anudeep,

This solution does not work because I am calling the flow from a VF not from the Aura component, how I can make the adjustment to this above VF page so it redirects me back to the current opportunity page? 

 
AnudeepAnudeep (Salesforce Developers) 
Hi Haseeb - Because your page has a controller, I suggest checking the examples in this post
Haseeb Ahmad 9Haseeb Ahmad 9
Hi Anudeep,

Thank you but This did not help me at all because I had this VF page before.
 
<apex:page controller="EngageDealSupportButtonClass" lightningstylesheets="true">
<apex:includeLightning />
<flow:interview name="pservicerequest" buttonLocation="bottom" finishLocation="/{!$CurrentPage.parameters.opportunityId}">
<apex:param name="opportunityId" value="{!$CurrentPage.parameters.opportunityId}"/>
</flow:interview>
</apex:page>

which was working perfectly fine in terms of directing me back to the recent record page but the problem with this page is it runs in classic runtime and I want the page to be run in lightning running before I change my page to run in lightning runtime but now the problem is I cannot able to redirect like before.

I hope that makes sense. any thoughts?