...
Code Block | ||||
---|---|---|---|---|
| ||||
@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('CallerIDSalesForceID'); String ServiceNumberCallerID = req.params.get('ServiceNumberCallerID'); String ServiceNameAgentUID = req.params.get('ServiceNameAgentUID'); // PerformDo SOSLsome Queryinteresting overlogic contactsto and leads, searching for determine the phoneservice number with *wildcards* String soslSearchStringserviceNumber = '*' + CallerID + '*'; List<List<SObject>> searchList = [FIND :soslSearchString IN ALL FIELDS RETURNING Contact, Lead]; 4980012345678'; List<Contact> contacts = ( (List<Contact>) searchList[0] ); List<Lead> leads = ( (List<Lead>) searchList[1] ); // Multple hits? if( contacts.size() + leads.size() > 1 ) { // Multiple hits res.statusCode = 300; 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()String serviceName = ''; List<String> fieldList = new List<String>( fieldSet ); String query = 'SELECT ' + String.join( fieldList, ',' ) + ' FROM Contact WHERE Id = \'' + Id + '\''; Contact contact = Database.query( query res.addHeader( 'Content-Type', 'application/json' ); // 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 nullres.responseBody = Blob.valueOf( '{ "ServiceNumber" : "' + serviceNumber + '", "ServiceName" : "' + serviceName + '" }' ); } } |
CURL Test
First of all, obtain an OAUTH Token, see Testing with CURL.
...