TransWikia.com

Need help finishing flow using ltng:outApp

Salesforce Asked by Merry Stambaugh on January 2, 2022

I am using the standard code provided by salesforce for the ltng:outApp. I need to have my flow close the window on finish for one flow, and navigate to the record created on another one.

I have read through a bunch of documentation, but I feel like all of the examples I find have the app created differently. I understand APEX and visualforce pretty well, but have never really created a lightning app.

<aura:application access="GLOBAL" extends="ltng:outApp" implements="ltng:allowGuestAccess">
<aura:dependency resource="lightning:flow"/>
</aura:application>

Here is the visualforce

<apex:page >
  <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



           }
        };
        $Lightning.use("c:lightningOutApp", function() {
           // Create the flow component and set the onstatuschange attribute
           $Lightning.createComponent("lightning:flow", {"onstatuschange":statusChange},
              "flowContainer",
              function (component) {

                 
                 // Start an interview in the flowContainer div, and 
                 // initializes the input variables.
                 component.startFlow("My_flow");
              }
           );
        });
     </script>
      
  </body>

I have tried adding something similar to this to navigate to the created record, but I am not sure what needs to be set in my flow for this to work..

I cannot find anything that has worked to close the window when completed. In my old VF page I had it redirect to a page that was used javascript to close the window, but that does not see to work… or I am not redirecting correctly using navigateToUrl

   if(event.getParam("status") === "FINISHED") {
  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();
     }
  }

}

One Answer

If you go to the force:navigateToURL documentation https://developer.salesforce.com/docs/component-library/bundle/force:navigateToURL/documentation

In the last line it says "This event is handled by the one.app container. It’s supported in Lightning Experience, Salesforce app, and Lightning communities."

So force:navigateToURL will only work in one.app container because there are listeners to respond to that event.

You can find this limitation mentioned in Lightning out considerations and Limitation section of Aura component developer guide.

https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/lightning_out_considerations.htm

Is visualforce page is really required in your case to call flow ? Where exactly you are trying to surface this vf page. I can think of a way of getting rid of visualforce page at all if its not necessary and directly calling the flow in lightning component. If that component is meant to be surfaced in salesforce lightning tab or lightning app builder or lightning record pages then I think navigateToURL event will work after flow finish.

Answered by SushantN on January 2, 2022

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP