site logo

Act On It

Build Custom Apex Actions

Developers can create actions using apex to handle unique requirements not supported by declarative tools.


To get started:


  1. Create an Apex class implementing the "ActOnIt.ActOnItMessageAction" interface. Only classes with this interface will be available when configuring a message action.
  2. Implement the execute method which gets called when the action executes:


global interface ActOnItMessageAction {

   global ActOnItMessageActionResult execute(
       String userId,  
       String messageLogId,
       String messageTypeId,  
       String messageActionId,
       List<Id> relatedRecordIds
   );
}


The Apex Class and 'execute' method must use the ‘global’ access modifier to ensure the action is visible to the Act On It framework.


The execute method parameters provide useful context:

  • userId - The ID of the user who launched the action.
  • messageLogId - The message log record ID.
  • messageTypeId - The message type record ID.
  • messageActionId - The message action record ID.
  • relatedRecordIds - The IDs of related records.


Return an ActOnIt.ActOnItMessageActionResult instance to report the results of the action:


global with sharing class ActOnItMessageActionResult {

   global Boolean isSuccess;
   global String errorMessage;
   global String successMessage;
   global String navigateToRecordId;

   global ActOnItMessageActionResult(Boolean isSuccess, String errorMessage, String successMessage) {
       this.isSuccess = isSuccess;
       this.errorMessage = errorMessage;
       this.successMessage = successMessage;
   }
}


  • isSuccess - Denotes if action succeeded.
  • errorMessage - Custom error message string.
  • successMessage - Custom success message string.
  • navigateToRecordId - Salesforce record ID to redirect the user.


Here's an example of a custom apex action class:


global class MyCustomAction implements ActOnIt.ActOnItMessageAction {
   global ActOnIt.ActOnItMessageActionResult execute(
       String userId,
       String messageLogId,
       String messageTypeId,
       String messageActionId,
       List<Id> relatedRecordIds
   ) {
       Boolean isSuccess;
       String errorMessage;
       String successMessage;

       // Execute your custom Apex activity here.

       return new ActOnIt.ActOnItMessageActionResult(isSuccess, errorMessage, successMessage);
   }
}


Once the Apex class is created, you can begin creating an "Act On It" action that will execute the code when selected by a user.


To create an 'Apex' action, follow these steps:


  1. Navigate to the ‘Message Actions’ Tab (Act On It Lightning App > Application Settings > Message Actions) and click ‘New’.
  2. Select the "Apex" Record Type and select 'Next'.


yT3jWzu7WflWruAn4akQ9iY6PL0Kr3rwSbwCWtD4.png


Configure your action button with the following details:


  • Apex Class - Select your custom apex action class from the list of available options.
  • Action Label: Provide a meaningful name for the action. Customize the button further by selecting an icon from the ‘Icon Selection’ section.
  • API Name: Choose a unique name for the action, without spaces or special characters (except underscores). This name distinguishes between similar actions with a matching label.
  • Success Message - Provide a custom default success message.
  • Fail Message - Provide a custom default fail message.


Lastly, configure your Record Dependency settings and click "Save".


cl5zmJu1SCYXPyHDuRhC6JbE0WQ8alPlbLjIhcZi.png


Your Message Action is now ready to be applied to any Message Type with a matching data type. Admins have control over which actions are accessible to users via their User Settings.