3

We are trying to convert to the Salesforce lightning experience. One of the recent roadblocks is as simple as opening a new window or tab. The previously defined Java script button is now a lightning component used in a quick action. The need is to click a button, execute some validation and render a Visual force page as a PDF. When we use the Salesforce recommended "force:navigateToURL" the PDF is opened in the same window as the button originated. We would like to use a familiar 'window.open' but that is not recommended. If anyone has an idea how to open a new window\tab when a quick action button is clicked that would be great.

This is the component code we are currently trying to use:

var urlEvent = $A.get("e.force:navigateToURL");
urlEvent.setParams({
"url": '/apex/RenderAsPDFVisualforce?Id=' + recordId,
"target": "_blank"
});`
  • How did you achieve this ? – SFDC Apr 11 at 12:32
1

That should work. You just need to call urlEvent.fire(); as well.

  • 1
    Lightning Experience, non-console app, opened in same tab/window, but worked for my use case. Thanks to OP and @Ryan Villamin! – MayTheSForceBeWithYou Jul 15 at 17:52
1

If you are in a console app ( recommended ) , you can use lightning workspaceApi

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

Add the following line in your quickAction component

<lightning:workspaceAPI aura:id="workspace" />

Then you can request to open a new tab with your url

    var workspaceAPI = component.find("workspace");
    workspaceAPI.openTab({
        url: '/apex/RenderAsPDFVisualforce?Id=' + recordId,
        focus: true
    }).then(function(response) {
          // actions to do after opening tab if necessary
    }).catch(function(error) {
        console.log(error);
    });

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.