1

Trying to create an Action button to be placed on the record detail page, I want the functionality as click on that button, lightning component URL should open in a new window.

Using this link: /lightning/cmp/c__NewCase?recordId=Id which is opening in that tab itself while window open behavior is set to be open in a new window.

1
  • add picture of your button behavior? Standard Button by default open Lightning component in Dialog box May 31, 2019 at 11:10

2 Answers 2

2

in your case you should use lightning:workspaceAPI please use below solution and post if you get any errors. refer doc for workspaceAPI

cmp

<aura:component implements="flexipage:availableForAllPageTypes" access="global" >
<lightning:workspaceAPI aura:id="workspace" />
<lightning:button label="Open Tab" onclick="{! c.openTab }" />
</aura:component> 

controller.js

{(
openTab : function(component, event, helper) {
    var workspaceAPI = component.find("workspace");
    workspaceAPI.openTab({
        url: "/lightning/r/c__NewCase/+'yourrecordid'+/view",   // you should pass your recordId at yourrecordid
        focus: true
    }).then(function(response){
       // if any actions needed after opening a tab
    }).catch(function(error){
       console.log(error)// catch if any errors happened 
    });
},
)}
2
  • I can agree with the above method, but I want to open component with the button on the record detail page. So that I can set URL of my lightning component to be open and this component will open in new window or tab. Jun 5, 2019 at 13:54
  • can you post what you have tried so far, otherwise you want get much help from community.
    – sdandamud1
    Jun 5, 2019 at 14:10
0

Here are two Quick Action Button Lightning Component solutions to either open a pop-up window or new browser tab with a Visualforce Page (or whatever URL you want to redirect to):

Lightning Component:

<aura:component implements="force:lightningQuickAction,force:hasRecordId" access="global">
    <aura:handler name="init" action="{!c.openPage}" value="{!this}" />
</aura:component>

Controller (to open pop-up window):

({
    openPage : function(component,event){
        var w = 1020;
        var h = screen.height-120;
        var left = (screen.width/2)-(w/2);
        var top = 0;
        var recordId = component.get('v.recordId');
        //Open Pop-up Window with Visualforce Page
        window.open('/apex/YOUR_VISUALFORCE_PAGE?id='+recordId, 'Sales Contract', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
        //Close Action Button Modal
        $A.get('e.force:closeQuickAction').fire();
    }
})

Controller (to open new browser tab):

({
    openPage : function(component,event){
        var recordId = component.get('v.recordId');
        //Open New Browser Tab with Visualforce Page
        window.open('/apex/YOUR_VISUALFORCE_PAGE?id='+recordId,'_blank');
        //Close Action Button Modal
        $A.get('e.force:closeQuickAction').fire();
    }
})

You must log in to answer this question.

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