1

Is it possible to launch a Lightning page that was created in the Lightning App builder (composed of two sibling components) from the button click of another custom component? Any help would be greatly appreciated. Thanks

Controller code is shown below:

  openApp: function(component, event, helper) {
    var workspaceAPI = component.find("workspace");
    debugger;
    workspaceAPI.openTab({
        url:'lightning/n/ProductSelector_PopUp.app',
        focus: true

    }).then(function(response) {
        workspaceAPI.getTabInfo({
            tabId: response
        }).then(function(tabInfo){
               console.log("The recordId for this tab is: " + tabInfo.recordId); 
    });
    }).catch(function(error) {
        console.log(error);
    });
},

2 Answers 2

2

Actually with Summer 18, the preferred method is to start using the Navigation API. See here:

https://developer.salesforce.com/docs/atlas.en-us.214.0.api_console.meta/api_console/sforce_api_console_lightning_open_pagereference.htm

Use openTab() and openSubtab() with a lightning:isUrlAddressible component to open custom Lightning components in Lightning console apps.

Relevent release notes here:

https://releasenotes.docs.salesforce.com/en-us/summer18/release-notes/rn_lc_components_navigation.htm

https://releasenotes.docs.salesforce.com/en-us/summer18/release-notes/rn_console_open_lightning_pages_components_tabs_subtabs.htm

FYI: A huge benefit of this is if you've created a lightning app container just to house a component (because previously, that was the only way to navigate to a specific component on a full page), you can now use the navigation API to navigate to only the component (no un-necessary app container!).

For example, this is a valid url in the address bar now

https://dev.lightning.force.com/lightning/cmp/c__MyCustomComponent?c__ids=a101Y000004xhvlQAA
5
  • This is the way to go but still force:navigateToURL event is useful because sometimes, we might want to navigate from component to the app built by admins. By that way admins are free to improve app by adding more and more components. Commented Jul 2, 2018 at 17:39
  • @KiranMachhewar in that case, I think you can still navigate to the app with the following name c__MyAppBuiltByAdmins. See here: developer.salesforce.com/docs/atlas.en-us.214.0.lightning.meta/…
    – tsalb
    Commented Jul 2, 2018 at 17:49
  • Interesting.. Lets say you create app page named TestApp, basically its a flexi page not aura bundle. Do you have any working example for that, have you tried and tested it with Lightning app builder's app page ( flexi page )? I would love to see this in action, please share some code example. Commented Jul 2, 2018 at 20:04
  • @KiranMachhewar no sample needed, I just read the docs in further detail. You would use: standard__navItemPage and the attributes apiName: "TestApp"
    – tsalb
    Commented Jul 2, 2018 at 20:48
  • Let me give a try, once I get time Commented Jul 2, 2018 at 23:33
2

Yes, Just grab the relative url of the page created by Lightning App builder and use the workspace API to navigate.

Consider the app name is TestApp

Code should look like:

In component add :


    $A.get("e.force:navigateToURL").setParams({ 
       "url": "/lightning/n/TestApp" 
    }).fire();

5
  • Thanks Kiran, I've tried implementing your suggestion but it doesn't seem to be working. The relative URL I'm inputting seems to be the problem as the function doesn't compute to'true', to allow the 'then' clause to proceed. Any suggestions?
    – DimzeeD
    Commented Jul 2, 2018 at 14:09
  • What do you mean by function doesn't compute to true? Commented Jul 2, 2018 at 14:11
  • Did you wrap the url in single quotes? Commented Jul 2, 2018 at 14:12
  • I've added my Controller code to the question above for clarity
    – DimzeeD
    Commented Jul 2, 2018 at 14:27
  • @DimitriosKolovopoulos Apologies, previous solution was only working with Console App, your app is using standard navigation so please change the code as above and it should work now. I just tested it. Commented Jul 2, 2018 at 17:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .