Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Sv translation
languageen

Implementation

Classic

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

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

Lightning

Access Setup, and search for "Apex" in the search box.

Classic and Lightning

Create a new class. Add the following code:


Translations Ignore


Code Block
languagejava
titleSample Apex getCallerInformation


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 Test

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

Next, create a file on your local disk, containing the following example Callback event data in JSON:

Translations Ignore


Code Block
@RestResource(urlMapping='/jtelACD/createCallbackcreateVoiceMail')
global with sharing class JTELACD_CreateCallbackCreateVoiceMail {
      
          
    public class JTELCallbackJTELVoiceMail {
        public Integer  ID;
        public Integer  AcdEventsID;
        public String   Caller;
        public String   CallbackNumberServiceNumbersNumber;
        public String   ServiceNumbersName;
        public Integer  AcdGroupsID;
        public String   ServiceNumbersNumberAcdGroupsName;
        public String   ServiceNumbersNameAcdGroupsForeignSystemID;
        public IntegerString   AcdGroupsIDdtCallStart;
        public String   AcdGroupsNamedtCallEnd;
        public String   AcdGroupsForeignSystemIDSubject;
        public String   dtCallStartBody;
        public String   dtCallEndAttachment1;
        public String   SubjectAttachment2;
        public String   BodyAttachment3;
        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
            JTELCallbackJTELVoiceMail callbackvoiceMail = (JTELCallbackJTELVoiceMail) System.JSON.deserialize( req.requestBody.toString(), JTELCallbackJTELVoiceMail.class );
            res.statusCode = 200;
            Case newCase = new Case ( subject = callbackvoiceMail.Subject,
                                      ContactId = callbackvoiceMail.SalesforceId,
                                      Description = callbackvoiceMail.Body + '\r\nFile: ' + voiceMail.Attachment1,
                                      SuppliedPhone = '+' + callbackvoiceMail.CallbackNumberCaller );
            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 Test

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

Next, create a file on your local disk, containing the following example Callback event data in JSON:

Translations Ignore
Code Block
{
	"ID": 2496,
	"Body": "Caller: +4919998764321\nCall Start: 2021-11-07 18:38:19.031\nACD Group: Group 1 - BigShoes\nCallback Reason: Hangup in queue",
	"Caller": "+4919998764321",
	"Subject": "ACD: automatic callback (hangup in queue) for +4919998764321",
	"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
titleCURL - 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/createCallbackcreateVoiceMail"





Sv translation
languagede

Status
colourRed
titleThis page is only available in English

...