Events in Salesforce


Note: This article applies to PureCloud for Salesforce.

You can configure the integration to fire or listen for events either in the Salesforce console in Salesforce Classic or in all versions of Lightning Experience. The types of events and the way that you fire or listen for them depends on the Salesforce user interface that you use.

Note: This article is an advanced customization topic meant for developers familiar with Salesforce.

Through the event model in the Salesforce Console Integration Toolkit, the integration fires and listens for events being raised around status changes (such as Available, Busy, Away, Out of Office, and On Queue) and call activities (connected, disconnected, ACW required, ACW completed).

Developers can create Visualforce pages that use these events. To create an example Visualforce page that fires and listens for events, use this sample code:

<apex:page >
   <apex:includeScript value="/support/console/34.0/integration.js"/>
 
   <style type="text/css">
      .statusSelection {
         position: relative;
         display: block;
         padding-top: 6px;
      }
   </style>

   <script type="text/javascript">
 
 
   //Omni Status Map Ids are org specific
   var statusMap = {Omni:{available:"0N5j00000008QNQ" , queue:"0N5j00000008QMt"}, PureCloud:{available:"AVAILABLE", queue:"ON_QUEUE"}};
 
   function OutputToConsole(message){
      console.log(message);
      if(document.getElementById("OUTPUTCONSOLE").value != ""){
         document.getElementById("OUTPUTCONSOLE").value = document.getElementById("OUTPUTCONSOLE").value + " \r\n";
      }
 
      document.getElementById("OUTPUTCONSOLE").value = document.getElementById("OUTPUTCONSOLE").value + message;
   }

   function changeStatus(status) { 
      if(status == 'available'){
         sforce.console.fireEvent('inin.salesforce.constants.consoleevent.changestatus', statusMap.PureCloud.available , function(data){console.log(data);});
         sforce.console.presence.setServicePresenceStatus(statusMap.Omni.available);
      }else if(status = 'onQueue'){
         sforce.console.fireEvent('inin.salesforce.constants.consoleevent.changestatus', statusMap.PureCloud.queue , function(data){console.log(data);});
         sforce.console.presence.setServicePresenceStatus(statusMap.Omni.queue);
      }
   }
 
   sforce.console.addEventListener('inin.salesforce.constants.consoleevent.pc.UPDATE_STATUS', function(data){
      OutputToConsole(JSON.stringify(data));
   });
 
   sforce.console.addEventListener('inin.salesforce.constants.consoleevent.pc.INTERACTION_CONNECTED', function(data){
      OutputToConsole(JSON.stringify(data));
   });
 
   sforce.console.addEventListener('inin.salesforce.constants.consoleevent.pc.INTERACTION_DISCONNECTED', function(data){
      OutputToConsole(JSON.stringify(data));
   });
	
   sforce.console.addEventListener('inin.salesforce.constants.consoleevent.pc.ACW_REQUIRED', function(data){
      OutputToConsole(JSON.stringify(data));
   });
 
   sforce.console.addEventListener('inin.salesforce.constants.consoleevent.pc.ACW_COMPLETED', function(data){
      OutputToConsole(JSON.stringify(data));
   });

   </script>
   <span class="statusSelection">
      <input type="button" onclick="changeStatus('available')" value="Change status to Available" /> |
      <input type="button" onclick="changeStatus('onQueue')" value="Change Status to On Queue" />
   </span>
   <hr/>
   <span>
       <textArea id="OUTPUTCONSOLE" rows="20" cols="100" ></textArea>
   </span>
 
</apex:page>

For information about the Salesforce console, see Customize a Console with Custom Components in Salesforce Classic in the Salesforce documentation.

For information about using the event model, see the Salesforce Console Integration Toolkit for Salesforce Classic in the Salesforce documentation.

Events the integration fires

The integration can fire the following five events and send them to Salesforce.

Note: These event names begin with inin.salesforce.constants.consoleevent.pc., followed by the name in the table, for example, inin.salesforce.constants.consoleevent.pc.UPDATE_STATUS.
Event name Body example Description
UPDATE_STATUS

{
“reason”: “status_updated”,
“status”: “AVAILABLE”,
“id”: “44560c74-5e84-4062-94b6-5680cdeb54d5”,
“sub_status”: “Available Work At Home”
}

Status update. If using secondary statuses, the response includes secondary status information.
INTERACTION_CONNECTED {
“reason”: “connected”,
“interactionId”: “44560c74-5e84-4062-94b6-
5680cdeb54d5″
}
Interaction connected.
INTERACTION_DISCONNECTED {
“reason”: “disconnected”,
“interactionId”: “44560c74-5e84-4062-94b6-
5680cdeb54d5″
}
Interaction disconnected.
LOGGED_OUT {
“reason”: “logged_out”
}
User logged out.
ACW_REQUIRED {
“reason”: “acw_required”,
“interactionId”: “44560c74-5e84-4062-94b6-
5680cdeb54d5″
}
ACW required.
ACW_COMPLETED {
“reason”: “acw_completed”,
“interactionId”: “44560c74-5e84-4062-94b6-
5680cdeb54d5″
}
ACW completed.

Event the integration listens for

The integration can listen for the following event about status changes and change an agent’s status.

Note: This event name begins with inin.salesforce.constants.consoleevent., followed by the name in the table, for example, inin.salesforce.constants.consoleevent.changestatus.
Event name Body example Description
changestatus  {Status}

Status changes. Send the status ID in the request.

Note: If you only use primary statuses, you can send high-level key values in place of the status ID: ‘AVAILABLE’, ‘AWAY’, ‘BUSY’, ‘OUT_OF_OFFICE’, ‘ON_QUEUE’, ‘BREAK’, ‘TRAINING’, ‘MEETING’, ‘MEAL’.

Through the postMessage Web APIs, the integration can fire and listen for events being raised around status changes and subscriptions to Interaction, Notification, or UserActions events.

Events

Event name Description
Handshake If Enable Client Events is selected in the call center settings, the integration raises a handshake event whenever the client loads. The handshake event provides the context that Lightning components need to be able to fire events to the PureCloud for Salesforce client.
Interaction Fires interaction state changes. For more information, see the subscribe method in the PureCloud Embeddable Framework documentation (Developer Center).
Notification Fires notification state changes. For more information, see the subscribe method in the PureCloud Embeddable Framework documentation (Developer Center).
UserAction Fires user action state changes. For more information, see the subscribe method in the PureCloud Embeddable Framework documentation (Developer Center).
Note: All callback parameters described in the PureCloud Embeddable Framework documentation are available in the postMessage data payload along with the added root type. See the table under Communicate with PureCloud for Salesforce.

Administrators configure the call center settings so that the integration fires and listens for events.

Configure the integration

  1. Select Enable Client Events in the call center settings.

    This setting causes the integration to raise a handshake event whenever the client loads. 

  2. (Optional) Select other events (Interaction, Notification, and UserAction) to subscribe to. Click the right arrow to add them under Chosen.
  3. Click Save.
Note: If you add a Lighting component as a Utility Item to your Lightning app, be sure to select Start automatically. For more information, see Add a Utility Bar to Lighting Apps in the Salesforce documentation.

For more information, see Configure call center settings.

Communicate with PureCloud for Salesforce

The following table lists the available types that the PureCloud for Salesforce client listens for. These types are raised through the postMessage Web APIs. 

Type Body example
PureCloud.User.updateStatus {
type: “PureCloud.User.updateStatus”,
data: {
id: “<status ID or system presence>”
}
}

For more information about the integration, see About PureCloud for Salesforce.