ImplementationClassicTo create a new Apex class, access Setup in SalesForce, and type in "Apex" in the quick search box. Select "Build ... Develop ... Apex Classes". ![](/download/attachments/73498628/image2018-3-16%2016%3A55%3A53.png?version=1&modificationDate=1660068156000&api=v2)
LightningAccess Setup, and search for "Apex" in the search box. ![](/download/thumbnails/73498628/image2019-3-16_18-14-41.png?version=1&modificationDate=1660068156000&api=v2)
Classic and LightningCreate a new class. Add the following code:
Translations Ignore |
---|
Code Block |
---|
language | java |
---|
title | Sample Apex |
---|
| @RestResource(urlMapping='/jtelACD/createVoiceMail')
global with sharing class JTELACD_CreateVoiceMail {
public class JTELVoiceMail {
public Integer ID;
public Integer AcdEventsID;
public String Caller;
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 String Attachment1;
public String Attachment2;
public String Attachment3;
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
JTELVoiceMail voiceMail = (JTELVoiceMail) System.JSON.deserialize( req.requestBody.toString(), JTELVoiceMail.class );
res.statusCode = 200;
Case newCase = new Case ( subject = voiceMail.Subject,
ContactId = voiceMail.SalesforceId,
Description = voiceMail.Body + '\r\nFile: ' + voiceMail.Attachment1,
SuppliedPhone = '+' + voiceMail.Caller );
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. Warning |
---|
Note: this will NOT work if the SalesforceId field is not a valid contact in your Salesforce instance. Please bear this in mind, when executing the examples below. |
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 VoiceMail event data in JSON: Translations Ignore |
---|
Code Block |
---|
@RestResource(urlMapping='/jtelACD/createVoiceMail')
global with sharing class JTELACD_CreateVoiceMail {
public class JTELVoiceMail {
public Integer ID;
public Integer AcdEventsID;
public String Caller;
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 String Attachment1;
public String Attachment2;
public String Attachment3;
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
JTELVoiceMail voiceMail = (JTELVoiceMail) System.JSON.deserialize( req.requestBody.toString(), JTELVoiceMail.class );
res.statusCode = 200;
Case newCase = new Case ( subject = voiceMail.Subject,
ContactId = voiceMail.SalesforceId,
Description = voiceMail.Body + '\r\nFile: ' + voiceMail.Attachment1,
SuppliedPhone = '+' + voiceMail.Caller );
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() );
}
}{
"ID": 2496,
"Body": "Caller: +4919998764321\nCall Start: 2021-11-07 18:38:19.031\nACD Group: Group 1 - BigShoes\nVoice Mail left by caller",
"Caller": "+4919998764321",
"Subject": "ACD: voice mail from caller +4919998764321",
"Attachment1": "https://myjtelserver/CarrierPortal/ResourceDispatcher/clients/1/recordings/vm_anewfilename.wav",
"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": "+4919998764321",
"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, assuming the file created above was named: c:\temp\eventJSONData.json Translations Ignore |
---|
Code Block |
---|
title | CURL - getCallerInformation Test |
---|
| curl.exe -L --post302 --silent -i -X POST -d '@C:\temp\eventJSONData.json' --header "Content-Type: application/json" --header "Authorization: Bearer <OAUTH_TOKEN>" --header "Connection: Close" "https://<SALES_FORCE_INSTANCE_URL>/services/apexrest/jtelACD/createVoiceMail" |
|
Warning |
---|
Note: it will not be possible to download the voicemail file from this example. In a real voice-mail example, the file will have a different name. Also, note that it is necessary to be logged into jtel from within the salesforce instance otherwise the jtel portal will not allow downloading of the file. |
|