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:

  • insert
  • update
  • delete
  • merge
  • upsert
  • undelete

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?

I started thinking about other standard solutions, but neither Process Builder or Flows enable to reach my goal. That’s because what I want to handle is a client-side event and Salesforce does not provide any tools to insert custom javascript or browser code in a standard page (i.e. the Create page).

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.

How to do that? With an unexisting new tool that I like to call “browser triggers” . Just like apex triggers, browser triggers would interact with standard pages in order to manage front-end business logic. Javascript could be the main programming language, but additional frameworks like AngularJS or ReactJS might be valid alternatives to link the DOM with the Business Logic and the Data Model. Furthermore, nothing prevents Salesforce from inventing a new programming Language, just as it did for Apex.

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
  • Security problems. Actually, if I am not mistaken,  Salesforce removed the Javascript sidebar injection in order to avoid URL hack technique and cross domain javascript hack
  • Risk to manage business logic controls client-side instead of server-side

Keys Take Away

In my opinion, what Salesforce really misses is a client-side scripts management. Global frameworks like AngularJs and ReactJS are moving towards a single Javascript Page Application. “Browser triggers” could be a possible solution for Salesforce that will enable a good interaction between the client and the server.

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
(Visited 350 times, 1 visits today)
Francesco Boccassi
Francesco Boccassi

Francesco is what the business chemistry calls a blend between a Pioneer, always looking for the next generation idea, and a Driver, methodical and clear goal minded. With more than 6 years in consulting he has a deep knowledge of CRM and Salesforce. He is now focusing on Blockchain and DApps.

Leave a Comment