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
Brock IrvineBrock Irvine 

Having problems getting url redirect working.

I am trying to set a redirect url for when a flow finishes. The flow I'm using is running off of a visualforce page. I tried writing this code, but it doesn't seem to be working. It's getting into the statusChange method, but it's not redirecting. I followed the documentation found here as closely as possible:
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_flows_lightningruntime.htm

Code:
 
<apex:page standardController="Account" extensions="Log_A_Call_Controller">
    <head>
        <apex:slds />
    </head>
         <apex:includeLightning />
         <body class="slds-scope">
         <div id="flowContainer" />
         <script>
         var statusChange = function(event){
                      if(event.getParam("status") === "FINISHED"){
                          console.log('Flow is finished. Attempting Redirect');
                          var urlEvent = $A.get("e.force:navigateToURL");
                          urlEvent.setParams({
                              "url": "/home"
                          });
                          urlEvent.fire();
                      }
                  }
            $Lightning.use("c:Log_A_Call_Flow", function() {
               $Lightning.createComponent("lightning:flow",
               {"onstatuschange":statusChange}, "flowContainer",
                  function (component) {
                     // Set the input variables
                     var inputVariables = [ {
                           name: 'recordId',
                           type: 'String',
                           value: "{!accountId}",
                        },
                        {
                           name: 'URL',
                           type: 'String',
                           value: "{!URL}"
                        }
                     ];
                     // Start an interview in the flowContainer div, and 
                     // initializes the input variables.
                     component.startFlow("Log_A_Call", inputVariables);
                  }
               );
            });
         </script>
         </body>
</apex:page>
What am I missing here?
Best Answer chosen by Brock Irvine
AbhishekAbhishek (Salesforce Developers) 
Hi Brock,

According to Salesforce doc:

By default, when you embed a flow in a Visualforce page, the flow renders in Classic runtime. Like its name suggests, Classic runtime looks and feels like regular Visualforce pages and the Salesforce Classic desktop experience. If you want your flow to render in Lightning runtime in your Visualforce page, embed the flow Aura component to your Visualforce page.
Create a Lightning app that declares a dependency on the lightning: flow component.
Add the Lightning Components for Visualforce JavaScript library to your Visualforce page using the <apex:includeLightning/> component.
In the Visualforce page, reference the dependency app.
Write a JavaScript function that creates the component on the page using $Lightning.createComponent().
Please refer to the below links which might help you further with the above requirement.

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

https://salesforce.stackexchange.com/questions/201278/flow-in-visualforce-page-not-displaying-in-lightninglooks-like-classic

https://developer.salesforce.com/forums/?id=9060G000000BhIoQAK

https://help.salesforce.com/articleView?id=flow_distribute_runtime.htm&type=5

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks.

All Answers

AbhishekAbhishek (Salesforce Developers) 
Hi Brock,

According to Salesforce doc:

By default, when you embed a flow in a Visualforce page, the flow renders in Classic runtime. Like its name suggests, Classic runtime looks and feels like regular Visualforce pages and the Salesforce Classic desktop experience. If you want your flow to render in Lightning runtime in your Visualforce page, embed the flow Aura component to your Visualforce page.
Create a Lightning app that declares a dependency on the lightning: flow component.
Add the Lightning Components for Visualforce JavaScript library to your Visualforce page using the <apex:includeLightning/> component.
In the Visualforce page, reference the dependency app.
Write a JavaScript function that creates the component on the page using $Lightning.createComponent().
Please refer to the below links which might help you further with the above requirement.

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

https://salesforce.stackexchange.com/questions/201278/flow-in-visualforce-page-not-displaying-in-lightninglooks-like-classic

https://developer.salesforce.com/forums/?id=9060G000000BhIoQAK

https://help.salesforce.com/articleView?id=flow_distribute_runtime.htm&type=5

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks.
This was selected as the best answer
Brock IrvineBrock Irvine
Hi Abishek,

The lightning component embedded in the Visualforce page works like it should. The only bit I'm having problems on is the code for the redirect to the home screen. Particularly this snippet:
var urlEvent = $A.get("e.force:navigateToURL");
                          urlEvent.setParams({
                              "url": "/home"
                          });
                          urlEvent.fire();
                      }

My code seems to get into the conditional statement that this runs in, but this (for whatever reason) isn't redirecting to the home screen when executed. This is where I'm specifically having my problem.
AbhishekAbhishek (Salesforce Developers) 
Brock can you follow the above blog's suggestions it might help you.