Loading

Use JavaScript buttons with the Console Integration Toolkit

Publiceringsdatum: Jun 25, 2026
Beskrivning

The Salesforce Console Integration Toolkit (CTI) Developer Guide examples use Visualforce pages, which employ Smart HTML. Smart HTML can detect and call methods regardless of their load order. However, JavaScript button scripts use standard HTML, where the order of script loading matters. This article applies to Salesforce Classic only, as JavaScript buttons are not supported in Lightning Experience.

Lösning

Why Load Order Matters in JavaScript Buttons

The Salesforce Console Integration Toolkit allows developers to customize the console and integrate third-party systems. The developer guide provides examples using Visualforce pages. In Visualforce, Smart HTML handles the order of script and component loading automatically, so a CTI method can be called before the required script has loaded — Visualforce will locate the script regardless.
In contrast, when you use a JavaScript button to implement a CTI method, standard HTML is used. This means scripts must be loaded before any methods that rely on those scripts are called.

Key Difference: Script Load Order
In a Visualforce page, calling testOpenPrimaryTab() before the integration.js script loads works correctly because Smart HTML resolves the dependency automatically.
In a JavaScript button script, you must use REQUIRESCRIPT('/support/console/38.0/integration.js') at the very beginning of your script to ensure the library loads first. Only after that should you define your callback functions (such as an openSuccess function that reports whether the tab opened successfully) and then call sforce.console.openPrimaryTab().

Summary
When using CTI Developer Guide examples outside of a Visualforce page, always ensure that scripts are loaded before the methods that depend on them are called.
Look at these two examples:   

CTI Developer Guide Example using Visual Force Page:

<apex:page standardController="Case">

// Note that method is called before script is loaded-  Works fine in Visual Force page! 
     <A HREF="#" onClick="testOpenPrimaryTab();return false"> 
         Click here to open a new primary tab</A> 

    <apex:includeScript value="/support/console/38.0/integration.js"/>
    	<script type="text/javascript">
        		function testOpenPrimaryTab() {
            	//Open a new primary tab with the salesforce.com home page in it
            	sforce.console.openPrimaryTab(null, 'http://www.salesforce.com', false, 
                	'salesforce', openSuccess, 'salesforceTab');
        	}
        
        	var openSuccess = function openSuccess(result) {
            	//Report whether opening the new tab was successful
            	if (result.success == true) {
                		alert('Primary tab successfully opened');
            	} else {
                		alert('Primary tab cannot be opened');
            	}
        		};     
  	</script>
</apex:page>

 

Example for Javascript, like you might use for button script:

{!REQUIRESCRIPT("/support/console/38.0/integration.js")}

   var openSuccess = function openSuccess(result) {
   //Report whether opening the new tab was successful
   if (result.success == true) {
      alert('Primary tab successfully opened');
   } else {
      alert('Primary tab cannot be opened');
   }
   };

// Notice here that method is called AFTER script is loaded.  Javascript needs this!  

   sforce.console.openPrimaryTab(null, 'http://www.salesforce.com', false, 'salesforce',    openSuccess, 'salesforceTab');

 

Knowledge-artikelnummer

000383520

 
Laddar
Salesforce Help | Article