function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ArunaAruna 

how to replace window.open(vfpage url?id='xxxx') on custom button in lighting custom button

Hello everyone,

now we are moving from classic to lighting I need to convert all the javascript button to lighting.
We have a custom button which has below url on it

window.open('/apex/vfpagename?id=xxxxx'); 
User-added image
how do I replace window.open  in lighting and I want the button to work both in lighting and in classic.
Can any please help me on this if any sample code will be appreciated.

Thank you,
Aruna.
 
Best Answer chosen by Aruna
ArunaAruna
Solution :-

Create a global action and call below lighting component.

Lighting Component

<aura:component controller="ProductInUseCntrl2" Implements="flexipage:availableForAllPageTypes,force:lightningQuickAction,force:hasRecordId" access="global" >
 <!--<lightning:button label="Open in new Window" onclick="{!c.openActionWindow}"/>-->
    
    <aura:handler name="init" value="{!this}" action="{!c.openActionWindow}"/>

</aura:component>

Java script controller

({
    openActionWindow : function(component, event, helper) {
        
        // var accId=component.get("v.recordId");
        window.open( "/apex/vfpageName?id=" + component.get("v.recordId"));
        //window.close();
      $A.get("e.force:closeQuickAction").fire();
    }
})

The only problem with this is unable to close the global action window
User-added image

can anyone, please correct me my code to close quick action window.

All Answers

Raj VakatiRaj Vakati
Use this code  and create a quick action with lightning 

 
<aura:component implements="force:lightningQuickActionWithoutHeader,force:hasRecordId">
               
	    <aura:handler name="init" value="{!this}" action="{!c.navigate}"/>
		   
 </aura:component>
({
 navigate : function(component, event, helper) {

    //Find the text value of the component with aura:id set to "address"
    var address = component.find("address").get("v.value");

    var urlEvent = $A.get("e.force:navigateToURL");
    urlEvent.setParams({
      "url": '/apex/vfpagename?id=' + component.get("v.recordId");
    });
    urlEvent.fire();
},
})

Refer this links

https://nebulaconsulting.co.uk/insights/lightning-experience-configuration-converter/

https://developer.salesforce.com/blogs/2018/06/convert-javascript-buttons-to-lightning-friendly-alternatives-with-the-lightning-experience-configuration-converter.html

https://github.com/developerforce/LEXComponentsBundle/blob/master/force-app/main/default/aura/redirectConditionalUrl/redirectConditionalUrlHelper.js
 
ArunaAruna
Hi,

I did try your solution it's not working getting below error message 

Unfortunately, there was a problem. Please try again. If the problem continues, get in touch with your administrator with the error ID shown here and any other related details.
Action failed: forceChatter:lightningComponent$controller$doInit [Right-hand side of 'instanceof' is not an object]
quickActionHandlerHelper.js failed to create component - forceChatter:lightningComponent

this quick action should on the Account object


<aura:component implements="force:lightningQuickActionWithoutHeader,force:hasRecordId">
        <aura:handler name="init" value="{!this}" action="{!c.navigate}"/>
 </aura:component>

({
 navigate : function(component, event, helper) {
    //Find the text value of the component with aura:id set to "address"
    var address = component.find("address").get("v.value");
    var urlEvent = $A.get("e.force:navigateToURL");
    urlEvent.setParams({"url":'/apex/productInUse?id=' + component.get("v.recordId")});
    urlEvent.fire();
},
})

 
ArunaAruna
Solution :-

Create a global action and call below lighting component.

Lighting Component

<aura:component controller="ProductInUseCntrl2" Implements="flexipage:availableForAllPageTypes,force:lightningQuickAction,force:hasRecordId" access="global" >
 <!--<lightning:button label="Open in new Window" onclick="{!c.openActionWindow}"/>-->
    
    <aura:handler name="init" value="{!this}" action="{!c.openActionWindow}"/>

</aura:component>

Java script controller

({
    openActionWindow : function(component, event, helper) {
        
        // var accId=component.get("v.recordId");
        window.open( "/apex/vfpageName?id=" + component.get("v.recordId"));
        //window.close();
      $A.get("e.force:closeQuickAction").fire();
    }
})

The only problem with this is unable to close the global action window
User-added image

can anyone, please correct me my code to close quick action window.
This was selected as the best answer