Handling custom Javascript buttons in Lightning

Sending mails to user on the click of a button from the detail page of a record, Creating a button that opens a popup dialog with a welcome message containing the user's first name, or creating a link that displays a country-specific Google map. We have been performing many such complex tasks in Salesforce Classic for years using custom Javascript buttons.

With Lightning taking up the whole world by storm and being cited as the future of salesforce, many customers are curious to know how these tasks would be performed in Lightning Experiance given the unavailability of Javascript Buttons. One of the most refreshing and unique things that Lightning experience offers is the ability to add Lightning components on the record, home, and other pages in the Salesforce application. As opposed to using In-Line Javascript which has access to Document Object Model (DOM) and Browser Object Model (BOM) whereby a malicious user using Cross Site Scripting(XSS) can access to the DOM or BOM and can change, or delete almost anything found in an HTML or XML document. Salesforce is already in the process of making Lightning components more secure. It is in the process of restricting javascript's uncontrolled access enabling Faster security review (AppExchange), better JS development practices while preventing XSS, Calling undocumented/private APIs and similar security issues etc.

Let’s take one of the most common use case of javascript button where customers want users to create or update records, but they also want to make sure that some of the fields are filled in or pre populated with certain criteria. Declarative tool like Quick Actions can be used in this case.

If users require an action to close a task without going through the edit page, and also want to make sure that task contains the due date before it is completed, then they can create a new action for the Task object.

To create a new action:

  1. Go to Task Buttons, Links, and Actions from object management settings for activities.
  2. Click New Action and select Action type as Update a Record.
  3. In label type Closing task and then Save.
  4. Select the fields you want to make required or read-only. In this example, the Due date is made required.
  5. In this example, predefined value of status field is set to Completed.
  6. After saving the quick action, you can add predefined field values for any of the fields. In this example, predefined value for task status is set to Completed.
  7. Add this action to the Task page layout for users.

Custome JavaScript Button image1

This is just the one example described, but there can exist many other common use cases for JavaScript buttons where quick actions can help you perform those. Quick actions can help you easily migrate your custom JavaScript button functionality using declarative approach that will work in both Salesforce Classic and Lightning Experience.

Similarly, some customers use JavaScript buttons for navigation, using the command window.open(URL) along with some variables to redirect users to another page. Most of these use cases can be achieved instead through custom URL buttons in Lightning Experience.

Apex triggers are an another alternative which can also be set up to execute before or after a user clicks Save on a record.

Another useful feature in Winter ’17 for Lightning Experience is support for using Visualforce buttons on list views. With this feature, you can use existing Visualforce actions in Lightning and work with multiple records in lists. For many use cases the above mentioned alternatives could be used to replace JavaScript Buttons. As far as advanced use cases are concerned, Lightning Actions which are easy to build being based on the quick action framework, and are set up similar to Visualforce quick actions also serve the purpose of being a common replacement to JavaScript Buttons.

For any query on Handling Custom Javascript Buttons In Lightning, contact support@astreait.com