NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

@RestResource(urlMapping = '/omnichannel/task') // This opens the endpoint at /services/apexrest/omnichannel/task
global class OmniChannelTaskService {

// Inner class to represent the request body for deserialization
private class OmniTaskRequest {
public String type; // Type of communication
public List<String> recipients; // List of emails or numbers
public String origin; // Origin emailbox
public String title; // Subject or title
public String body; // Body of the message
public String accountNumber; // account number of the cliente
}

// Inner class for the response that will be sent back
global class TaskResponse {
public String status; // Success or failure
public String message; // Message providing more context
public String taskId; // ID of the Task that was created (if successful)
}

// Method to handle POST requests
@HttpPost
global static TaskResponse createTask() {
// Initialize the response object
TaskResponse response = new TaskResponse();

try {
// Parse the request body (JSON to Apex Object)
String requestBody = RestContext.request.requestBody.toString();
OmniTaskRequest taskRequest = (OmniTaskRequest) JSON.deserialize(requestBody, OmniTaskRequest.class);

// Validate that all required fields are present in the request
if (isEmpty(taskRequest.type) || isEmpty(taskRequest.title) || isEmpty(taskRequest.body)) {
RestContext.response.statusCode = 400; // Bad Request
response.status = 'Error';
response.message = 'Missing required fields: type, title, or body.';
return response;
}

// Create a new Task record
Task newTask = new Task();
// Set required fields - mandatory fields
newTask.Subject = taskRequest.title; // The title sent in the request
newTask.ActivityDate = Date.newInstance(2040, 12, 30); // Static date for now
newTask.Priority = 'Normal'; // Static priority
newTask.OwnerId = '005Qs000002WsYnIAK'; // Static Owner ID (your User ID for now)
newTask.RecordTypeId = '0127Q0000013ViQQAU'; // Standard Task record type

// Set the custom fields sent by the Omni-channel team
//newTask.OMNI_Type__c = taskRequest.type; // Maps to "Tipo De Comunicação"
//newTask.OMNI_recipients__c = String.join(taskRequest.recipients, ', '); // Combines recipients into a string
//newTask.OMNI_originMailbox__c = taskRequest.origin; // Maps to "Emailbox de Origem"
newTask.Description = taskRequest.body; // Maps to "Description" (standard Salesforce field)

// Insert the Task into Salesforce
insert newTask;

// Populate the response with success status
response.status = 'Success';
response.message = 'Task created successfully';
response.taskId = newTask.Id;
RestContext.response.statusCode = 201; // HTTP 201 Created

return response;

} catch (Exception e) {
// Handle any unexpected errors
RestContext.response.statusCode = 500; // Internal Server Error
response.status = 'Error';
response.message = 'An internal error occurred: ' + e.getMessage();
return response;
}
}
// Helper method to check if a string is null or empty
private static Boolean isEmpty(String str) {
return str == null || str.trim().length() == 0;
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.