Thursday, May 23, 2013

Use A Free Account and Start Developing for Service Cloud Console and Open Cti

Got some emails from some developers, thanks for the feedback. It seems that a lot of people may not know a developer account is totally free. You can sign up for a developer org here.

With the account, you'll then follow the instructions to setup service cloud console. Remember to make the app available to your user account like this (Create -> Apps -> [Edit] Sample Console):



Once you have the service cloud console app created, you can follow the instruction to setup open cti:
Setup Open CTI Call Center and Developer Environment

You may also find our How To Build An Open Cti Integration From Scratch series useful.

Happy developing.

Sunday, May 19, 2013

How To Build An Open Cti Integration From Scratch In Service Cloud Console -- The Step by Step Guide. #2 Dynamically Get Context Data


If you haven't, please check out the "part 1, hello world" if necessary.




Get the current console page dynamically:


The open cti apis has a very important function: getPageInfo(). It returns information about the current page as a JSON string. Let's try to use it:
Let's edit the openctiDemo.html in part 1. Make the content look like:

<html>
<head>
</head>
<body>
<input type="button" onclick="javascript:alertPageInfo()" value="PageInfo"/>
</body>
<script type="text/javascript" src="https://MyInstance.salesforce.com/support/api/27.0/interaction.js"></script>
<script type="text/javascript" src="./js/demo.js"></script>
</html>

We'll also need a demo.js file:

var alertPageInfo  = function () {
sforce.interaction.getPageInfo(getPageInfoCallback);
}

var getPageInfoCallback = function (response) {
if (response.result) {
pageInfo = response.result;
alert(pageInfo);
} else {
alert(response.error);
}
}

Now if we open our console, you have a dummy button. Clicking on it you'll see this:


Nothing to be excited yet, but at least we are getting the context when we trigger an action.

Get relavant data from salesforce:


Another important/useful function in the open cti apis is runApex(). The function Executes an Apex method from an Apex class that’s exposed in Salesforce. If you are not sure what Apex is, see “Apex Code Overview” in the Salesforce online help.

The syntax of runApex is:
sforce.interaction.runApex(apexClass:string, methodName:string, methodParams:string, (optional) callback:function)

In this example, I have a pre-defined apex class MyUtils, which contains a method called getPhoneNumberByEntityId. This method will return a phone number associated with the record we pass in.

Now let's modify our demo.js file's getPageInfo() callback like:

var getPageInfoCallback = function (response) {
if (response.result) {
pageInfo = response.result;
               var entityId = JSON.parse(pageInfo).objectId;

sforce.interaction.runApex('MyUtil', 'getPhoneNumberByEntityId', "entityId=" + entityId, apexCallback);
else {
alert(response.error);
}
}

Next step is more exciting: we'll add an apexCallback to handle the data from the salesforce system. We'll cover it in the next article.