Wondering how to build apps without JavaScript buttons in Lightning Experience? In this blog post, we’ll show you how to quickly build alternative buttons with Sample Components for Lightning Component Actions. The Sample Components for Lightning Component Actions are a collection of code samples hosted in a GitHub repository and created specifically to help your JavaScript button use cases become compatible with Lightning Experience.

In Salesforce Classic, JavaScript buttons are popular as they serve an important purpose. With JavaScript buttons, you invoke inline JavaScript code via a button or a link. This is helpful for use cases like pre-populating new records during record creation, updating records based on logic, and integrating with an external system or platform.

However, JavaScript buttons are no longer supported in Lightning and will not show up when you transition to Lightning. This is because JavaScript buttons present many security challenges including:

  • Untrusted JavaScript from multiple sources and authors posing significant security challenges
  • Cross-component access
  • Over time, custom one-off JavaScript code gets obsolete and unmanageable

There are equally good alternatives available in Lightning via actions.

Actions in Lightning

Quick actions are declarative and can be easily and quickly configured by an Administrator without writing a single line of code. Quick actions can be used for simple use cases like:

  • Creating a record
  • Updating a record

For more complex use cases, we recommend you use Lightning component actions, which require some coding. With Lightning component actions, you call a pre-written Lightning component with the click of a button. You can use Lightning component actions for complex use cases, for example:

  • Validating data or prepopulating values inline
  • Feedback and confirmation messages
  • Third-party integration

Introducing Sample Components for Lightning Component Actions

You may have held off on transitioning to Lightning because of the effort required to build Lightning component-based alternatives to JavaScript buttons. If this is you, we have some great news! In order to make this aspect of Lightning transition that much easier, we are releasing a set of Lightning components you can build from called “Sample Components for Lightning Component Actions.” This components bundle is hosted as a GitHub repository available here.

The repository contains example components to help you build Lightning component actions of some of the most common use cases seen with JavaScript buttons. These components are fully functional and you can use them as-is or modify them to meet your needs.

The code samples cover these three common use cases:

  1. Dialogues
  2. Conditional URL
  3. Mass updates

Using the provided code samples, you can easily and quickly create Lightning actions that provide the same functionality that JavaScript buttons did in the Salesforce Classic interface.

There are three ways to use the code samples:

  1. Install to your Salesforce DX environment
  2. Install the LEXComponentsBundle unmanaged package to your Salesforce org.
  3. Use the code directly from the GitHub repository

The Update Opportunity Probability Lightning Action

Conclusion

The Documentation page of the GitHub repository has instructions to help you start using the code samples. With this GitHub repository, we hope that you will be able to quickly develop workarounds for JavaScript buttons and accelerate your transition to Lightning Experience. If you have any questions, please post them to the Lightning Now! Trailblazer community.

Authors:
Hemant Bedekar, Product Manager
Vin Addala, Product Manager

Get the latest Salesforce Developer blog posts and podcast episodes via Slack or RSS.

Add to Slack Subscribe to RSS