A few days ago I was working with Apex code to develop a complex piece of business logic. In the midst of this creative endeavor, I came to realize that I simply couldn’t make it work. All I wanted to do was show a field dynamically pre-filled on the standard “Create” form. To my chagrin, I learned that I couldn’t work client-side intercepting the OnCreate Event. That’s because Browser Triggers do not exist!
What do I mean for OnCreate Event?
Before continuing, I want to explain what I mean with OnCreate Event. As you probably know, Salesforce provides a powerful tool to intercept CUD (Create, Update, and Delete) events: Apex Trigger. In details, Apex Triggers enable you to perform custom actions before or after the following types of operations:
Salesforce manages these operations server-side, so they are triggered only after the user has submitted the operation. Actually, I would have wanted to insert the business logic as soon as the Create form had appeared. Unfortunately, no standard methods exist to accomplish it.
Do any other standard tools exist to do it?
The only way is to write a custom Visualforce Page or a Lightning Component Page. Obviously, it requires much more effort and it doesn’t allow to exploit all the features and error handlers that Salesforce natively provides on standard pages.
The importance of browser triggers events
I want to draw your attention to the importance of a browser script event.
Web pages, platforms, and even Salesforce (with Lightning) are increasingly focused on User Experience, by providing a catchy and interactive User Interface. Users expect to be lead by the User Interface, in order to intuitively understand their next best action. In a Web-based context, browser scripts gain importance.
Frameworks like AngularJS and ReactJS are changing the way to develop browser scripts, speeding up users’ actions and creating one-page applications. Based on the well-known Salesforce’s strategy to shift to Lightning Experience, it could be significantly helpful providing developers of standard tools to incept client-side logic in standard pages.
Browser triggers advantages
In the following list you can find some of the advantages related to browser triggers that came up to my mind:
- Pre-valuing text fields and picklists directly on the standard creation page (i.e. fill a child field with a parent’s field value and show it to the User)
- Managing syntax checks client-side and not server-side
- Showing alert messages and confirm messages on standard pages
- Making real-time read-only on standard pages
- Hiding and unhiding sections or fields based on users’ interactions on standard pages
- Dynamic CSS styling
- Could improve performances
Browser triggers limits
Of course, if Salesforce has not yet provided this capability (actually, Salesforce removed it in previous releases), it probably depends on a reason. Some of the limits could be related to:
- Compatibility of browser triggers across all the channels: Classic, Lightning and Salesforce1. Especially the last one could meet some problems to render browser scripts in the right way, even if platforms like Cordoba and Ionic are doing it successfully
- Risk to manage business logic controls client-side instead of server-side
Keys Take Away
Despite some barriers to consider, there are a lot of benefits that will improve the User Experience and the UI interaction.
Support us with a small donation:
- LTC Address: La5f6W1rPr5VHFGCrCmPJ3sSa2AiwKZJbU
- BTC Address: 1FG1j42MUze8jiW7JbgNaUMZxZeu7M1b4f
- Ripple Address: rPVMhWBsfF9iMXYj3aAzJVkPDTFNSyWdKy Tag: 562614972
- ETH Address: 0x0940958167ca9cbd6409999957a011be7907d904