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
Tom HoodTom Hood 

Lightning Experience replacements for OnClick Javascript Custom buttons

Our organization currently uses OnClick Javascript custom buttons for most of our tasks (phonecalls, contact management, events, etc.), and looking to the future and potential of Salesforce Lightning, we would like to begin the migration process, however we need replacements for our buttons. I've been browsing around on the forums here for a few days and it seems like people have has sucess using visualforce pages, flows, and lightning component ui:buttons, so I'm curious as to which one might be the best choice for our organization, and also what the differences between them are. We are looking for one that functions and codes similarly to the classic Javascript buttons. 

As an example, here is the code to one of our buttons. This code is for our "in progress" button, which is clicked whenever a contact is being called during an event, and the click removes the contact from the call list so that the person is not called twice or at the same time.

/* This code allows the javascript to access the API and push data into the Org.*/ 
{!requireScript("/soap/ajax/10.0/connection.js")}; 
sforce.connection.session = "{!$Api.Session_ID}"; 

function updateTask( ) 

try 

var task = new sforce.SObject("Task"); 
task.Id = "{!Task.Id}"; 
task.Status = "In Progress"; 
task.OwnerId = "{!User.Id}"; 
var result = sforce.connection.update([task]); 
if (result[0].getBoolean("success") == false ) { 
alert(result[0].errors.message); 
return; 

window.top.location.href=window.top.location.href; 

catch (e) { 
alert(e); 
}


updateTask();

If I was to rewrite this as a visualforce page, flow, or lightning component ui:button, how would I go about that? Any help is greatly appreciated. Thank you.
Darshan Gandhi 9Darshan Gandhi 9

Tom Hood - I think you can start with lighting buttons and use custom code and controller to migrate the existing code. 
Lighting buttons (https://developer.salesforce.com/docs/component-library/bundle/lightning:button/example)
You can have several references from aura doc. just use  AURA DOCS (https://your lightning host name /auradocs/reference.app)
 
Also, you can look into trailhead courses to begin with Component + Controller (https://trailhead.salesforce.com/en/content/learn/modules/lex_dev_lc_basics/lex_dev_lc_basics_controllers). Now if you want to call backend service , you can write <aura:component controller="Your apex class name" /> and then call method from controller using actions in salesforce

 

Let me know if you  need more help and 

 

Please select as best answer if it helped you