Mise en œuvrePour 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 ImplementationTo 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: Translations Ignore |
---|
| Sample Apex writeCallStatisticsExemple d'écriture ApexCallStatistics |
| @RestResource(urlMapping='/jtelACD/writeCallStatistics') |
global with sharing class JTELACD_WriteCallStatistics { |
public static DateTime convertISO8601( |
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! |
}JTELCallStatistics { public String SalesForceID; |
public String AgentUID; public |
classJTELCallStatistics{
public String ServiceNumber; public String | ServiceName; public String | SalesForceID
public String AcdConfigurationGroupsName; public String | dtCallStart; public String | AgentUID
public String dtCallConnected; public String dtCallEnd; | bOutbound
public Integer CONNRES; public Integer | CallerIDTransactionCodeExportKey; |
} @HttpPost global static String doPost() { RestRequest | publicStringServiceNumber
RestResponse res = RestContext.response; try { // | publicStringServiceName;
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 |
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: Translations Ignore |
---|
Code Block |
---|
language | powershell |
---|
title | CURL - |
---|
|
| writeCallStatistics Testé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" |
|
|