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:
To publish Act On It messaging using apex:
ActOnIt.ActOnItMessageManager.SingleMessageWrapper message;
message = new ActOnIt.ActOnItMessageManager.SingleMessageWrapper(
messageTypeDeveloperName,
messageString,
recordIds,
userOrGroupIds,
excludedUserIds,
source,
sendDateTime
);
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.
}
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.