Skip to main content

Opening Primary or subtab in the console through hyperlink Formula fields (eliminating Javascript hyperlink formula field)

From Spring 17, A URL for the HYPERLINK function can not contain JavaScript. This change was done to increase the security of the salesforce org.

 

Before this change, When we want to open contact screen as subtab in the console, we could use Javascript Hyperlink Formula field  like

HYPERLINK("javascript:if(typeof(srcUp)=='function') {srcUp('/003/e?isdtp=vw&accid=" & Id & "');}"+
" else {window.location.href='/003/e?accid=" & Id & "'}","Create Contact","_self")

After Spring 17, To open the same in subtab, we need to implement the solution using visualforce

To open Contact screen as primary tab.

1. Create a formaula filed with hyper link function which calls the VF page "OpenContact" and pass the required parameters

HYPERLINK("/apex/OpenContact?id="& ContactId & "&caseid="& Id,"Contact Detail",'_self')

2. In the VF page, Open the contact as primary / sub tab

window.onload = function () {

sforce.console.openPrimaryTab(null, "https://****-****.my.salesforce.com/{!id}", true);
window.history.back();

}   

Note: We have used window.history.back() to move to the initial state of the tab. If you remove this, you will get the content of this VF page.

In case the request is coming from Salesforce 1, Instead of Window.history.back(), you can use sforce.one.back() method.

Comments