Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Content imported from a Scroll Translations translation file.
Sv translation
languageen

Implementation

To create a new Apex class, access Setup in SalesForce, and type in "Apex" in the quick search box. 

Select "Build ... Develop ... Apex Classes".

Create a new class. Add the following code:

Translations Ignore


Code Block
languagejava
titleSample Apex writeCallStatistics
@RestResource(urlMapping='/jtelACD/writeCallStatistics')
global with sharing class JTELACD_WriteCallStatistics {
     
     
    public static DateTime convertISO8601( String iso8601_ts ) {
        DateTime dt = (DateTime) JSON.deserialize( '"' + iso8601_ts + '"', DateTime.class );
        return DateTime.newInstance( dt.getTime() );
        // NOTE: return dt does not work!
    }     
    
    public class JTELCallStatistics {
        public String SalesForceID;
        public String AgentUID;
        public Integer bOutbound;
        public String CallerID;
        public String ServiceNumber;
        public String ServiceName;
        public String AcdAgentGroupsName;
        public String AcdConfigurationGroupsName;
        public String dtCallStart;
        public String dtCallAlert;
        public String dtCallConnected;
        public String dtCallEnd;
        public Integer nDuration;
        public Integer CONNRES;
        public Integer Cause;
        public String TransactionCodeExportKey;
    }
     
    @HttpPost
    global static String doPost() {
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
 
        try {
            // Deserialize the JSON
            JTELCallStatistics callStatistics = (JTELCallStatistics) System.JSON.deserialize( req.requestBody.toString(), JTELCallStatistics.class );
             
            // Create a new task, and full some of the fields
            if( ( callStatistics.CONNRES == 1 ) ) {
                Datetime dtConnected          = convertISO8601( callStatistics.dtCallConnected );
                Task task                     = new Task();
                task.ActivityDate             = dtConnected.date();
                task.CallDisposition          = 'Completed';
                task.Subject                  = 'Call with Agent ' + callStatistics.AgentUID;
                task.Description              = 'Agent Group ' + callStatistics.AcdAgentGroupsName + '\r\nConfiguration ' + callStatistics.AcdConfigurationGroupsName;
                task.CallType                 = callStatistics.bOutbound <> 0 ? 'Outbound' : 'Inbound';
                task.CallDurationInSeconds    = callStatistics.nDuration;
                task.Status                   = 'Completed';
                task.Type                     = 'Call';
         
                // Link to sales force record
                task.WhoId                    = callStatistics.SalesForceID;
             
                // Insert
                insert task;
            }
        }
        catch( Exception e ) {
            res.statusCode = 500; // Internal server error
            return e.getMessage();
        }
 
        // All OK
        res.statusCode = 200;
        return null;
    }
}



CURL Test

First of all, obtain an OAUTH Token, see Testing with CURL.

The following CURL command can be used to test this API:

Translations Ignore


Code Block
languagepowershell
titleCURL - writeCallStatistics Test
curl --silent -i -X POST -d '{ "SalesForceID" : "<SalesForceRecordId>", "AgentUID" : "test.agent@example.com", "bOutbound" : 0, "CallerID" : "4989461495011", "ServiceNumber" : "49800123456", "ServiceName" : "Test Service", "AcdAgentGroupsName" : "Sales", "AcdConfigurationGroupsName" : "Sales", "dtCallStart" : "2018-03-16T16:45:00", "dtCallAlert" : "2018-03-16T16:45:02", "dtCallConnected" : "2018-03-16T16:45:10", "dtCallEnd" : "2018-03-16T16:50:10", "nDuration" : 300, "CONNRES" : 1, "Cause" : 16, "TransactionCodeExportKey" : "Offer Made" }' --header "Content-Type: application/json" --header "Authorization: Bearer <OAUTH_TOKEN>" --header "Connection: Close" "https://<SALES_FORCE_INSTANCE_URL>/services/apexrest/jtelACD/writeCallStatistics"




Sv translation
languagede

Status
colourRed
titleThis page is only available in English

Sv translation
languagefr

Mise en œuvre

Pour créer une nouvelle classe Apex, accédez à Setup dans SalesForce, et tapez "Apex" dans la boîte de recherche rapide. 

Sélectionnez "Construire ... Développer

Implementation

To create a new Apex class, access Setup in SalesForce, and type in "Apex" in the quick search box. 

Select "Build ... Develop

... Apex Classes".

Image Modified

Create a new class. Add the following code:

Créer une nouvelle classe. Ajoutez le code suivant:

Sample Apex writeCallStatistics
Translations Ignore


Code Block
languagejava
title
Exemple d'écriture ApexCallStatistics
@RestResource(urlMapping='/jtelACD/writeCallStatistics')
 global with sharing class JTELACD_WriteCallStatistics {
 public static DateTime convertISO8601( 
String iso8601_ts ) 
public static DateTime convertISO8601( String iso8601_ts ) { DateTime
{ DateTime dt = (DateTime) JSON.deserialize( '"' + iso8601_ts + '"', DateTime.class );
 
return DateTime.newInstance( dt.getTime() );
 
// NOTE: return dt does not work!
 } public class 
}
JTELCallStatistics { public String SalesForceID; 
public String AgentUID; public 
Integer bOutbound; 
public 
class
String 
JTELCallStatistics
CallerID; 
{
public String ServiceNumber; public String 
ServiceName; public String 
SalesForceID
AcdAgentGroupsName;
 public String AcdConfigurationGroupsName; public String 
dtCallStart; public String 
AgentUID
dtCallAlert;
 public String dtCallConnected; public String dtCallEnd; 
public Integer 
bOutbound
nDuration;
 public Integer CONNRES; public Integer 
Cause; public String 
CallerID
TransactionCodeExportKey;
 } @HttpPost global static String doPost() { RestRequest 
public
req 
String
= 
ServiceNumber
RestContext.request;
 RestResponse res = RestContext.response; try { // 
public
Deserialize 
String
the 
ServiceName;
JSON JTELCallStatistics callStatistics = 
public String AcdAgentGroupsName; public String AcdConfigurationGroupsName; public String dtCallStart; public String dtCallAlert; public String dtCallConnected; public String dtCallEnd; public Integer nDuration; public Integer CONNRES; public Integer Cause; public String TransactionCodeExportKey; } @HttpPost global static String doPost() { RestRequest req = RestContext.request; RestResponse res = RestContext.response; try { // Deserialize the JSON JTELCallStatistics callStatistics = (JTELCallStatistics) System.JSON.deserialize( req.requestBody.toString(), JTELCallStatistics.class ); // Create a new task, and full some of the fields if( ( callStatistics.CONNRES == 1 ) ) { Datetime dtConnected = convertISO8601( callStatistics.dtCallConnected ); Task task = new Task(); task.ActivityDate = dtConnected.date(); task.CallDisposition = 'Completed'; task.Subject = 'Call with Agent ' + callStatistics.AgentUID; task.Description = 'Agent Group ' + callStatistics.AcdAgentGroupsName + '\r\nConfiguration ' + callStatistics.AcdConfigurationGroupsName; task.CallType = callStatistics.bOutbound <> 0 ? 'Outbound' : 'Inbound'; task.CallDurationInSeconds = callStatistics.nDuration; task.Status = 'Completed'; task.Type = 'Call'; // Link to sales force record task.WhoId = callStatistics.SalesForceID; // Insert insert task; } } catch( Exception e ) {
(JTELCallStatistics) System.JSON.deserialize( req.requestBody.toString(), JTELCallStatistics.class ); // Create a new task, and full some of the fields if( ( callStatistics.CONNRES == 1 ) ) { Datetime dtConnected = convertISO8601( callStatistics.dtCallConnected ); Task task = new Task(); task.ActivityDate = dtConnected.date(); task.CallDisposition = 'Completed'; task.Subject = 'Call with Agent ' + callStatistics.AgentUID; task.Description = 'Agent Group ' + callStatistics.AcdAgentGroupsName + '\r\nConfiguration ' + callStatistics.AcdConfigurationGroupsName; task.CallType = callStatistics.bOutbound <> 0 ? 'Outbound' : 'Inbound'; task.CallDurationInSeconds = callStatistics.nDuration; task.Status = 'Completed'; task.Type = 'Call'; // Link to sales force record task.WhoId = callStatistics.SalesForceID; // Insert insert task; } } catch( Exception e ) { res.statusCode = 500; // Internal server error
 
return e.getMessage();
 }
 
// All OK
res.statusCode = 200;
 res.statusCode = 200; return null;
 } 
}
}



Test CURL

TestFirst of all, obtain an OAUTH Token, see 

Tout d'abord, obtenez un jeton OAUTH, voir Testing with CURL.

The following CURL command can be used to test this API:

La commande CURL suivante peut être utilisée pour tester cette API:

writeCallStatistics Test
Translations Ignore


Code Block
languagepowershell
titleCURL -
écrire le test CallStatistics
curl --silent -i -X POST -d '{ "SalesForceID" : "<SalesForceRecordId>", "AgentUID" : "test.agent@example.com", "bOutbound" : 0, "CallerID" : "4989461495011", "ServiceNumber" : "49800123456", "ServiceName" : "Test Service", "AcdAgentGroupsName" : "Sales", "AcdConfigurationGroupsName" : "Sales", "dtCallStart" : "2018-03-16T16:45:00", "dtCallAlert" : "2018-03-16T16:45:02", "dtCallConnected" : "2018-03-16T16:45:10", "dtCallEnd" : "2018-03-16T16:50:10", "nDuration" : 300, "CONNRES" : 1, "Cause" : 16, "TransactionCodeExportKey" : "Offer Made" }' --header "Content-Type: application/json" --header "Authorization: Bearer <OAUTH_TOKEN>" --header "Connection: Close" "https://<SALES_FORCE_INSTANCE_URL>/services/apexrest/jtelACD/writeCallStatistics"