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
mritzimritzi 

Lightning replacement of following onClick JavaScript button

I have tried to get a replacement of following onClick JavaScript button in Lightning, but so far I haven't been able to make progress.
 
{!REQUIRESCRIPT("/soap/ajax/31.0/connection.js")}
{!requireScript("/soap/ajax/31.0/apex.js")}



if("{!Opportunity.Number_of_Quotes__c}"=="0"){
alert("There must be atleast one Quote");
}
else{
window.open('/_ui/core/email/author/EmailAuthor?&p26={!Opportunity.Logged_In_User_Email__c}&p2_lkid={!Opportunity.AccountId}&p3_lkid={!Opportunity.Id}&template_id={!$Label.Quote_Template}&retURL=%2F{!Opportunity.Id}')

}

Any help would be highly appreciated
Alain CabonAlain Cabon
Hi,

JavaScript buttons in Lightning don't work anymore nor connection.js. 

JavaScript Buttons: It’s Time to Move On: In fact, you might be reluctant to migrate to Lightning Experience because JavaScript buttons aren’t supported. 
https://trailhead.salesforce.com/en/modules/lex_javascript_button_migration (https://trailhead.salesforce.com/fr/modules/lex_javascript_button_migration)

You have to play with events that fire the navigation targets (force:navigateToXXXX) in a client-side controller writen in javascript working with a server-side controller in apex for accessing the data.
Now you will get the value of Opportunity.Number_of_Quotes__c in your javascript controller calling the apex controller for reading the object with its fields.

Like here: https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/apex_records.htm

Best regards
Alain
mritzimritzi
Hi Alain,

The link explain the common use cases.

In my case, it's a mix of two things. I want to validate a field on the existing record and give a poup message if the value is 0. else I have to redirect the user to an email template with pre populated fields.

If you can guide me in right direction, that would be great.
Alain CabonAlain Cabon
Hi,

I am very interested in the solutions developed for LEX (ligthning experience). I develop currently more and more in LEX and I hope other developers will also help us here.

The problem here is the button itself because the (quick)actions have their constraints in LEX.

Where is your current button used? list, detail, visualforce page ? (snapshot? complete code?)

Indeed, the common use cases don't show clearly in the documentation how to replace a simple button with a LEX component because only the action button are well placed on the page. You don't want a simple standard quick action because you want to test a value.

We will develop a simple component of type "Ligjtning Quick Action" at first because you can easily attach a button to it.

Developer console: 

User-added image

<aura:component implements="force:lightningQuickAction" >
    Hello everybody!
</aura:component>

A new action (any object):  

User-added image

User-added image

Add the action on the layout:

User-added image

Switch to LEX: 

User-added image

This new button is working but it does .. nothing.

The big problem is starting now because we have to complete to code of the LEX component and I can help you.

<aura:component implements="force:lightningQuickAction" >
    ...
</aura:component>

but I need to know where is your button first ?

We will code a complete solution together for your problem (with the help of other people here probably for better direction, simpler perhaps).

Best regards
Alain
Alain CabonAlain Cabon
Lightning Quick Action and  Developer console: New > Lightning Component (for a new lightning bundle)
(typos above)
Regards
mritzimritzi
It is on the Detail Page
Alain CabonAlain Cabon
Ok and what object?
mritzimritzi
It is on Opportunity object