Salesforce Javascript Buttons

Javascript buttons are buttons that are shown on a record that execute the configured Javascript when clicked. In this post, I’ll cover benefits and drawbacks. For how to configure one, see Create a Custom Button in Salesforce and other resources.

Benefits

  • Fast Development. Enter the javascript to run, click the button, verify functionality, repeat until working as designed.
  • Can execute web services. One can create a Salesforce web service in Apex that can then be invoked from a record. This is useful for doing various processing on a record. For example, the candidate has been approved and now you want to update the status and email the individual in one button click.

Drawbacks

  • UX Experience calling web services. If the web service does a moderate level of processing, the user may have to wait seconds for the operation to complete. Salesforce doesn’t automatically update the UI to indicate that something is happening. It’s up to the developer to update the UI to reflect the processing is in-progress and to notify the user with a message of the operation’s success or failure.
  • Have to add dependent libraries like JQuery through RequireScript syntax or other means. Open jQuery Dialog from Custom Button for more info.
  • Cross-Browser Compatibility.  While ubiquitous  across browsers, Javascript feature support still varies so ensure that your code works in the Salesforce supported browsers like Chrome, Firefox, and Edge. ECMAScript 6 Compatibility has a nice matrix showing the capabilities of browsers as of April 2016.

Overall, Javascript buttons are sweet. They are good for light to moderately complex operations. For more complex ones, use a Visualforce or Lightning page to handle it.

What do you think of Javascript buttons? What other benefits and drawback would you consider? Also, how often do you use them?

Happy Coding,

Luke

Leave a Reply

Your email address will not be published. Required fields are marked *