0

I have 2 existing VFP pages (Page 1 and page 2 ) which are super complex and we are moving to LEX.

When page 1 Loads, it has 2 buttons, Next and Cancel.

When Next button is clicked, it is moving to Page 2 and from there we save the records. I was able to open Page 1 in Lighting console with the help of NavigateToURL.

Later I realized that Next and Cancel button wont work as expected since we are in LEX. If next button is clicked, the 2nd page is opening in classic view (this is the issue I need to voercome .I need the next page also open in Lightning tab with the help of workspace API). So what I did is, Created a simple App with Lightning out and put 2 Buttons ( Next and cancel ). Updated my VFP something like this.

<apex:page >
PAGE 1
<apex:includeScript value="/lightning/lightning.out.js" />
<apex:includeLightning />
<script>
    $Lightning.use("c:LEXOUT_APP", function() {
      $Lightning.createComponent("c:LEX_ROUTING",
      { label : "" },
      "My_DIV_ID",
      function(cmp) {});
    });
</script>
<form>
    COMPLEX LOGICS WHICH I DONT HAVE PROBLEM WITH SO FAR
    <apex:pageBlock title="My Content" rendered="{!$User.UITheme == 'Theme3'}">
        **This is classic view so hide the orignal Next and Cancel buttons.**
</apex:pageBlock>
<apex:pageBlock title="My Content" rendered="{!$User.UITheme == 'Theme4u'}">
               **This is lightning ... So load my component which has Next and Cancel.**                  
             <div id="My_DIV_ID"></div> </apex:pageBlock></form></apex:page>

Now the component with Lightning Out loads as expected. But on click of next button, I have controller.js method which will do as below

<lightning:workspaceAPI aura:id="workspace" />
<button class="slds-button slds-button_neutral" onclick="{!c.handleClick}">Go to Page 2/NEXT</button>

handleClick : function(component, event, helper) {
    var urlEvent = $A.get("e.force:navigateToURL");
    urlEvent.setParams({
        "url": "/apex/Page_2?Id=**SOMEDetails**",
        "isredirect": "true"
    });
    urlEvent.fire();
},

But now I am getting this error on click of next button.

This page has an error. You might just need to refresh it. Action failed: c:LEX_ROUTE$controller$handleClick [urlEvent is undefined] Failing descriptor: {c:LEX_ROUTE$controller$handleClick}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.