Publish Act On It alerts with Apex
Salesforce developers can use apex code to publish Act On It messages to support complex automation requirements. By publishing Act On It message from apex you immediately benefit from Act On It's advanced alerting capabilities, such as the ability to:
- Deliver push notifications via Act On It's native alerts console.
- Enable or disable additional messaging channels with a single click.
- Enable users to opt in/out and personalize delivery.
- Plug-in custom alert actions to streamline next steps.
- To track and report on message delivery and engagement.
- Activate/deactivate the alerts without coded changes.
To publish Act On It messaging using apex:
- Construct a "Single Message Wrapper" as follows:
ActOnIt.ActOnItMessageManager.SingleMessageWrapper message;
message = new ActOnIt.ActOnItMessageManager.SingleMessageWrapper(
messageTypeDeveloperName,
messageString,
recordIds,
userOrGroupIds,
excludedUserIds,
source,
sendDateTime
);
- The "SingleMessageWrapper" is an inner class of "ActOnItMessageManager" class and represents a single message to be delivered to one or more recipients.
- The constructor properties are as follows.
- messageTypeDeveloperName - String - Required. This links the message to a predefined Message Type. The Message Type's developer name can be found here:
- messageString - String - Optional. Override the default message from the Message Type. Useful for creating dynamic, personalized messages featuring Salesforce data.
- recordIds - List of Ids- Optional. Links the message to one or more Salesforce records.
- userOrGroupIds - List of Ids- Required. The target user/group IDs to receive the message.
- Excluded Recipients - List of Ids - Deprecated. We recommend using "Message Opt Outs" instead.
- source - String - Optional. Helps track messages for reporting.
- sendDateTime - DateTime - Optional. Schedules the message for future delivery.
- Build List of Message Wrappers
- Create a list of SingleMessageWrapper entities:List<ActOnIt.ActOnItMessageManager.SingleMessageWrapper> messages = new List<ActOnIt.ActOnItMessageManager.SingleMessageWrapper>();
- Add a wrapper entry for each message that needs to be published.
- Call Validate and Publish Method
- Pass the messages and allOrNone (boolean) flag to validateAndPublishMessages()
- allOrNone means all messages must pass validation before any are published. Default is false (i.e. partial failures will be permitted).List<ActOnIt.ActOnItMessageManager.PassOrFail> results;
results = ActOnIt.ActOnItMessageManager.validateAndPublishMessages(messages, allOrNone); - As seen above, the method will return pass or fail results for each message.
global class PassOrFail{
global Integer isSuccess; //Denotes the success of the action.
global Integer message; //Contains details of any failures.
global Boolean index; //The result index.
}
- Handle Response
- Loop through and inspect the results.
- Check isSuccess flags for errors
- Access index to map results back to original messages
Here's an example of a coded action that sends a congratulatory message to sales reps for closing their sales Opportunities. We'll selectively include their manager for the higher value deals:
//Create your list of messages.
List<ActOnIt.ActOnItMessageManager.SingleMessageWrapper> messages = new List<ActOnIt.ActOnItMessageManager.SingleMessageWrapper>();
//Loop through newly closed won Opportunities.
for(Opportunity o : closedWonOpps){
//Create a message for each opportunity.
ActOnIt.ActOnItMessageManager.SingleMessageWrapper message = new ActOnIt.ActOnItMessageManager.SingleMessageWrapper(
//messageTypeDeveloperName - Specify the Developer Name of the applicable Message Type.
System.Label.Big_Deal_Message_Type_Dev_Name,
//messageString - Override the Message Type's default with a personalized message.
'Great Job '+o.Owner.FirstName+'! Congratulations on closing the \''+o.Name+'\' deal!',
//recordIds - Link the message to the Opportunity for quick navigation and custom actions.
new List<Id>{o.Id},
//userOrGroupIds - Add the Opportunity Owner as a recipient.
new List<Id>{o.OwnerId},
//excludedUserIds - No exclusions required.
null,
//source - Apply a source for reporting & troubleshooting purposes.
'Opportunity Update Trigger',
//No sendDateTime required as we wish to publish the message immediately.
null
);
//For higher value deals add the Opportunity Owner's Manager as an additional recipient.
if(o.Amount > bigDealThreshold) message.userOrGroupIds.add(o.Owner.ManagerId);
//Add the message to the message list.
messages.add(message);
}
if(messages.size()>0){
//Enable partial failures so individual failures do not prevent successful messages from being published.
Boolean allOrNone = false;
//Publish the messages and collect the results.
List<ActOnIt.ActOnItMessageManager.PassOrFail> results = ActOnIt.ActOnItMessageManager.validateAndPublishMessages(messages,allOrNone);
//Loop through the results and handle any failures.
for(ActOnIt.ActOnItMessageManager.PassOrFail result : results){
//Handle any validation errors.
if(!result.isSuccess){
system.debug('There was an error publishing the message for '+messages[result.index].recordIds[0]+'>'+result.message);
}
}
}
By constructing Message Wrappers and utilizing the ActOnItMessageManager, developers gain fine-grained control to publish Act On It messages from any Apex context.
This empowers organizations to build sophisticated flows for notifying stakeholders to drive action across business processes.