2

We are using a VF page as a CTI adapter. It does not seem to include sforce.one. I notice on other VF pages this is brought in as part of api.js, but I cannot put my finger on what it is about that VF page which brings in api.js when the CTI adapter page does not bring it in.

How do I access sforce.one from my VF page acting as a CTI adapter? Would it be a horrible idea to bring it in explicitly myself, as in

<apex:includeScript value="/sforce/one/50.0/api.js"/>

1 Answer 1

3

The recommended approach is documented in the Open CTI developer guide here

Using the below imports in Lightning Experience brings in the required sforce dependency

<apex:page>
      <script src="/support/api/50.0/lightning/opencti_min.js" type="text/javascript"></script>
 ...
 </apex:page>

I tested by creating a simple vf page as shown below with the call center config as here

    <apex:page >
  <!-- Begin Default Content -->
    <h1>Sample Page in CTI!</h1>
    <!-- End Default Content -->
     <HTML>
      <head>
       <!-- Imports Open CTI JavaScript library. Point to a valid Salesforce 
  domain.
  -->
    <script src="https://domain:port/support/api/50.0/lightning/opencti_min.js">.    </script>
  <script type="text/javascript">
   // Callback of API method: setSoftphonePanelHeight
    var setSoftphonePanelHeightCallback = function(response) {
        // Returns true if setSoftphonePanelHeight method is executed successfully, false otherwise
        if (response.result) {
           alert('setSoftphonePanelHeight is successfully executed.');
        } 
  };
   // Invokes API method: setSoftphonePanelHeight
   function setSoftphonePanelHeight() {
     sforce.opencti.setSoftphonePanelHeight({
        heightPX: 500,
        callback: setSoftphonePanelHeightCallback
     });
  }
   // Callback of API method: setSoftphonePanelWidth
       var setSoftphonePanelWidthCallback = function(response) {
        // Returns true if setSoftphonePanelWidth method is executed successfully, false otherwise
        if (response.result) {
           alert('setSoftphonePanelWidth is successfully executed.');
        } 
        else {
           alert('setSoftphonePanelWidth failed.');
        }
  };
   // Invokes API method: setSoftphonePanelWidth
   function setSoftphonePanelWidth() {
     sforce.opencti.setSoftphonePanelWidth({
        widthPX: 500,
        callback: setSoftphonePanelHeightCallback
       });
    }
  </script>
 </head>
<body>
  <button onclick="setSoftphonePanelHeight();">setSoftphonePanelHeight({heightPX:500}). 
 </button><br/>
   <button onclick="setSoftphonePanelWidth();">setSoftphonePanelWidth({widthPX:500})</button><br/>
   </body>
  </html>
</apex:page>

You can use the sforce.opencti.publish method to publish an LMS event directly to an LWC component that can be on the app page!

LWC component can help with you all the functions like navigation, refreshing or any other thing you need sforce.one for.

sforce.one is only available on top frame in lightning experience or in the Salesforce mobile app container

You can bring in sforce lib as you have mentioned in query but it is not documented method

3
  • Thank you very much. Could you kindly confirm that you also have access to sforce.one, since we need that to use LMS (sforce.one.publish)? We were actually already bringing in opencti.js, and we see sforce, but not sforce.one.
    – kamezaburo
    Dec 14, 2020 at 1:41
  • I found out I can use sforce.opencti.publish. See developer.salesforce.com/docs/atlas.en-us.api_cti.meta/api_cti/….
    – kamezaburo
    Dec 14, 2020 at 2:19
  • 1
    Exactly I was about to update this! You can use LMS there and use publish and then once in LWC you don't need sforce.one for anything! Dec 14, 2020 at 2:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .