Sv translation |
---|
|
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: Translations Ignore |
---|
Code Block |
---|
language | java |
---|
title | Sample Apex |
---|
|
|
| getCallerInformation | @RestResource(urlMapping='/jtelACD/ |
| getCallerInformationonClickToDial')
global with sharing class JTELACD_ |
| GetCallerInformation OnClickToDial{
@HttpGet
global static |
| Stringvoid doGet() {
RestRequest req = RestContext.request;
RestResponse res = RestContext.response;
// This is how to access URLParams if required
// List<String> URLParams = req.requestURI.split('/');
// Example: ["","jtelACD"," |
| getCallerInformationonClickToDial"]
// Extract the request parameters
String |
| CallerIDSalesForceID = req.params.get(' |
| CallerIDServiceNumberCallerID = req.params.get(' |
| ServiceNumberServiceNameAgentUID = req.params.get(' |
| ServiceNamePerformSOSLQueryovercontactsand leads, searching for phone with *wildcards*soslSearchString'*' + + '*'List<List<SObject>>searchList=[FIND:soslSearchString IN ALL FIELDS
RETURNING
Contact,
Lead]; List<Contact> contacts = ( (List<Contact>) searchList[0]res.addHeader( 'Content-Type', 'application/json' );
|
| List<Lead> leads res.responseBody = Blob.valueOf( |
| (List<Lead>) searchList[1] );
// Multple hits?
if( contacts.size() + leads.size() > 1 )
{
// Multiple hits
res.statusCode = 300'{ "ServiceNumber" : "' + serviceNumber + '", "ServiceName" : "' + serviceName + '" }' );
|
| return null;
}
if( contacts.size() > 0 )
{
// Query for exact contact
String Id = (String) contacts.get(0).get('Id');
Set<String> fieldSet = schema.describeSObjects(new String[] { 'Contact' } )[0].fields.getMap().keyset();
List<String> fieldList = new List<String>( fieldSet );
String query = 'SELECT ' + String.join( fieldList, ',' ) + ' FROM Contact WHERE Id = \'' + Id + '\'';
Contact contact = Database.query( query );
// 200 OK will be returned by default
return JSON.serialize( contact );
}
if( leads.size() > 0 )
{
// Query for exact lead
String Id = (String) leads.get(0).get('Id');
Set<String> fieldSet = schema.describeSObjects(new String[] { 'Lead' } )[0].fields.getMap().keyset();
List<String> fieldList = new List<String>( fieldSet );
String query = 'SELECT ' + String.join( fieldList, ',' ) + ' FROM Lead WHERE Id = \'' + Id + '\'';
Lead lead = Database.query( query );
// 200 OK will be returned by default
return JSON.serialize( lead );
}
// Nothing found
res.statusCode = 404;
return null;
}
} |
CURL Test
First of all, obtain an OAUTH Token, see Testing with CURL.
The following CURL command can be used to test this API:
CURL TestFirst of all, obtain an OAUTH Token, see Testing with CURL. The following CURL command can be used to test this API: Translations Ignore |
---|
Code Block |
---|
title | CURL - onClickToDial Test |
---|
| curl.exe --silent -i -X GET --header "Authorization: Bearer <OAUTH_TOKEN>" --header "Connection: Close" "https://<SALES_FORCE_INSTANCE_URL>/services/apexrest/jtelACD/onClickToDial?SalesForceID=<SalesForceRecordID>&CallerID=49894614950701&AgentUID=admin" |
|
|
Sv translation |
---|
|
Status |
---|
colour | Red |
---|
title | This page is only available in English |
---|
|
|
Sv translation |
---|
|
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 ... Apex Classes". Image Added
Créez une nouvelle classe. Ajoutez le code suivant : Translations Ignore |
---|
Code Block |
---|
language | java |
---|
title | Exemple apex onClickToDial |
---|
| @RestResource(urlMapping='/jtelACD/onClickToDial') global with sharing class JTELACD_OnClickToDial{ @HttpGet global static void doGet() { RestRequest req = RestContext.request; RestResponse res = RestContext.response; // This is how to access URLParams if required // List<String> URLParams = req.requestURI.split('/'); // Example: ["","jtelACD","onClickToDial"] // Extract the request parameters String SalesForceID = req.params.get('SalesForceID'); String CallerID = req.params.get('CallerID'); String AgentUID = req.params.get('AgentUID'); // Do some interesting logic to determine the service number String serviceNumber = CallerID; String serviceName = ''; res.addHeader( 'Content-Type', 'application/json' ); res.responseBody = Blob.valueOf( '{ "ServiceNumber" : "' + serviceNumber + '", "ServiceName" : "' + serviceName + '" }' ); } } |
|
Test CURLTout d'abord, obtenez un jeton OAUTH, voir Testing with CURL. La commande CURL suivante peut être utilisée pour tester cette API: Translations Ignore |
---|
Code Block |
---|
title | CURL - Test onClickToDial |
---|
|
|
|
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/onClickToDial?SalesForceID=<SalesForceRecordID>&CallerID=49894614950701&AgentUID=admin" |
|
|
---|