ImplementationClassicTo create a new Apex class, access Setup in SalesForce, and type in "Apex" in the quick search box. Select "Build ... Develop ... Apex Classes".
LightningAccess Setup, and search for "Apex" in the search box.
Classic and LightningCreate a new class. Add the following code:
Translations Ignore |
---|
Code Block |
---|
language | java |
---|
title | Sample Apex getCallerInformation |
---|
| @RestResource(urlMapping='/jtelACD/createCallback')
global with sharing class JTELACD_CreateCallback {
public class JTELCallback {
public Integer ID;
public Integer AcdEventsID;
public String Caller;
public String CallbackNumber;
public String ServiceNumbersNumber;
public String ServiceNumbersName;
public Integer AcdGroupsID;
public String AcdGroupsName;
public String AcdGroupsForeignSystemID;
public String dtCallStart;
public String dtCallEnd;
public String Subject;
public String Body;
public Integer CreatingUsersID;
public String CreatingUsersUID;
public String CreatingUsersNickName;
public String TargetUsersID;
public String TargetUsersUID;
public String TargetUsersNickName;
public String SalesforceId;
public Integer SalesforceQueryResult;
}
@HttpPost
global static void doPost() {
RestRequest req = RestContext.request;
RestResponse res = RestContext.response;
try {
// Deserialize the JSON
JTELCallback callback = (JTELCallback) System.JSON.deserialize( req.requestBody.toString(), JTELCallback.class );
res.statusCode = 200;
Case newCase = new Case ( subject = callback.Subject,
ContactId = callback.SalesforceId,
Description = callback.Body,
SuppliedPhone = callback.CallbackNumber );
insert newCase;
res.responseBody = Blob.valueOf( System.JSON.serialize( newCase) );
}
catch( Exception e ) {
res.statusCode = 500; // Internal server error
res.responseBody = Blob.valueOf( e.getMessage() );
}
}
} |
|
This sample class will create a Case object, and attach it to the supplied ContactId provided in the SalesforceId field. The telephone number will be added to the field SuppliedPhone. CURL TestFirst of all, obtain an OAUTH Token, see Testing with CURL. Next, create a file on your local disk, containing the following example Callback event: Translations Ignore |
---|
Code Block |
---|
{"ID": 2496, "Body": "Anrufer: +49894614950701\nAnrufernummer: 49894614950701\nGesprächsbeginn: 2021-11-07 18:38:19.031\nACD Gruppe (Nummer): Group 1 - BigShoes ()\nRückrufgrund: Aufgelegt in Warteschleife", "Caller": "49894614950701", "Subject": "ACD: Automatischer Rückruf (aufgelegt Warteschleife) für +49894614950701", "dtCallEnd": "2021-11-07T18:38:32", "AcdEventsID": 2496, "AcdGroupsID": 235, "dtCallStart": "2021-11-07T18:38:19", "SalesforceId": "00Q1n00000LSL4WEAX", "AcdGroupsName": "Group 1 - BigShoes", "TargetUsersID": null, "CallbackNumber": "49894614950701", "TargetUsersUID": null, "CreatingUsersID": null, "CreatingUsersUID": null, "ServiceNumbersName": "Big Shoes Hotline", "TargetUsersNickName": null, "ServiceNumbersNumber": "49199510", "CreatingUsersNickName": null, "SalesforceQueryResult": 1, "AcdGroupsForeignSystemID": null} |
|
The following CURL command can be used to test this API: Translations Ignore |
---|
Code Block |
---|
title | CURL - getCallerInformation Test |
---|
| curl.exe --silent -i -X GET --header "Authorization: Bearer <OAUTH_TOKEN>" --header "Connection: Close" "https://<SALES_FORCE_INSTANCE_URL>/services/apexrest/jtelACD/getCallerInformation?CallerID=4989461495000&ServiceNumber=4980012345678&ServiceName=test" |
|
The following CURL command can be used to test this API with the additional parameters from Release 3.25 - 2021-07-02 and upwards: Translations Ignore |
---|
Code Block |
---|
title | CURL - getCallerInformation Test |
---|
| curl.exe --silent -i -X GET --header "Authorization: Bearer <OAUTH_TOKEN>" --header "Connection: Close" "https://<SALES_FORCE_INSTANCE_URL>/services/apexrest/jtelACD/getCallerInformation?CallerID=4989461495000&ServiceNumber=4980012345678&ServiceName=test&Function=testFunction&UserData=testUserData&UserData2=testUserData2&UserData3=testUserData3" |
|
|