We have Custom Javascript Button, we want to convert JavaScript button to Lightning button in Salesforce. How can we achieve this?

3 Answers 3


You can achieve this by creating a Lightning component containing a lightning:button and placing all your javascript logic inside his controller.

There are some great examples on how to do it available on trailhead.


As Nordine Hamache said Lightning Components are the new substitutes, but not all of your logic might be easily converted in a single Lightning Component because no URL hacks are supported anymore. You make use of them in your legacy code.

To work around that you could wirte more Lightning Components and orchestrate them or try to use actions.


JavaScript buttons are superseded by Lightning Components. Components encapsulate your logic and are provided supported APIs, which makes your solution more robust.

This blog series has a great explanation and some examples. https://developer.salesforce.com/blogs/developer-relations/2016/09/why-its-time-to-break-up-with-javascript-buttons-and-embrace-lightning.html

There's also a Trailhead module on this topic. https://trailhead.salesforce.com/modules/lex_javascript_button_migration

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.