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
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 ... Classes Apex ".

Image Added

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

Translations Ignore


Code Block
languagejava
titleExemple d'écriture ApexCallStatistics
@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; } }



Test CURL

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

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

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"