...
Access Setup, and search for "Apex" in the search box.
Classic and Lightning
We provide two examples here.
The first example queries email Task objects from the Salesforce systemCreate a new class. Add the following code:
Code Block | ||
---|---|---|
| ||
@RestResource(urlMapping='/jtelACD/genericQuerygetEmailTasks') global with sharing class JTELACD_GenericQueryGetEmailTasks { // Class to decode the parameters public class GenericQueryParams { public String Param1; public String Param2; public String Param3; public String Param4; public String Query; } @HttpPost global static String doPost() { RestRequest req = RestContext.request; RestResponse res = RestContext.response; // Deserialize the JSON (not used in this example - just for illustration purposes) GenericQueryParams genericQueryParams= (GenericQueryParams) System.JSON.deserialize( req.requestBody.toString(), GenericQueryParams.class ); // Find next task to schedule in jtel system. // Note - the exact logic of this will be dependent on the Salesforce installation - this is JUST AN EXAMPLE. List<Task> tasks = [SELECT FIELDS(STANDARD), TYPEOF Who WHEN Lead THEN FirstName, LastName, Email WHEN Contact THEN FirstName, LastName, Email END FROM Task WHERE Status = 'Inbound Email' WITH USER_MODE LIMIT 1]; if( tasks.size() >= 0 ) { return JSON.serialize( tasks[0] ); } res.statusCode = 404; return null; } } |
The second example sets Task objects to "In Progress" in Salesforce:
Code Block | ||
---|---|---|
| ||
@RestResource(urlMapping='/jtelACD/setEmailTaskStatus')
global with sharing class JTELACD_SetEmailTaskStatus {
// Class to decode the parameters
public class GenericQueryParams {
public String Param1;
public String Param2;
public String Param3;
public String Param4;
public String Query;
}
@HttpPost
global static String doPost() {
RestRequest req = RestContext.request;
RestResponse res = RestContext.response;
// Deserialize the JSON
GenericQueryParams genericQueryParams = (GenericQueryParams) System.JSON.deserialize( req.requestBody.toString(), GenericQueryParams.class );
Task task = [SELECT FIELDS(STANDARD) FROM Task WHERE id =: genericQueryParams.Param1];
task.Status = genericQuery.Param2;
update task;
return System.JSON.serialize(task);
}
} |
CURL Test
First of all, obtain an OAUTH Token, see Testing with CURL.
...