Friday, May 05, 2017

Javascript in Salesforce Formula Custom Field

Starting with the Spring ‘17 release*, we will begin a three-phase effort to eliminate the use of JavaScript in hyperlink formula fields.Read more...
With this implementation, we will no longer to use javascript in hyperlink custom field formula and will retrieve this error :
Error: Incorrect argument value for function operator '"xxxx"'. Javascript is not allowed.
But still for certain condition , we still need to implement javascript.In order to achieve this, we can call Visualforce page or html page(static resource) and execute javascript inside the page itself.

Example : I want a link that can open two window .Previously it can be achieve by using hyperlink below:

HYPERLINK("javascript:window.open('tel:+6xxxxxxxxx'); window.open('http://www.salesforce.com'); window.close();", IMAGE("/servlet/servlet.FileDownload?file=01526000000GsNh","Click To Call") , '_blank')

But now the above code no longer work.The workaround for this is to create a new Visualforce page that contains javascript like below :


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
<apex:page standardController="Lead" showHeader="false" standardStylesheets="false" sidebar="false">
<script>
window.onload = function () {
 
    window.onload = function () {
    window.open("tel:+6xxxxxxxxx");
    window.open("http://www.salesforce.com");
    window.close()
}
</script>
</apex:page>

In custom field we just point to our Visualforce page.

HYPERLINK("/apex/my_vf?Id=" & Id, IMAGE("/servlet/servlet.FileDownload?file=01526000000GsNh", "Click To call"))

The concept also work by using html page that store in Static Resource, but I personally think Visualforce page might be useful especially we can use standard controller which enable us to use object fields.

No comments:

Post a Comment