Custom Button with OnClick JavaScript in Lightning Experience


Client is a US based organization which provides cloud based Managed Solutions. They have clients from public and private sectors. They provide solutions on cloud-based business intelligence (BI) and big data analytics platform.


Client wanted us to change their two custom buttons according to Lightning Experience. The buttons had a content source of OnClick JavaScript and Salesforce Lightning Experience doesn’t support such custom buttons.
The JavaScript called two Visualforce pages on the condition of a checkbox field of the record and also passed the recordId into the URL of the VF pages.


As per our analysis of the given requirements, we found that this could be achieved through Lightning Components. We developed separate Lightning Components for each button on Enterprise license.
Each component had an attribute through which we got the recordId. In the controller of the component, we wrote the required JavaScript code to call the Visualforce pages in a pop-up window.
We also created an Apex controller for the components which returned the value of the checkbox field and also the base URL of the Salesforce instance.
An action was created on the appropriate object which initialised the component. The action was then placed on the record detail page layout.

JavaScript Button in Lighting Component Image


  • Custom buttons with OnClick JavaScript, although not supported in Lightning Experience, were implemented according to the requirement with the help of Lightning Components.
  • Now a user can feel better UI and Navigation experience.

For additional queries on migrating Javascript buttons to Lightning please contact