fferpcore.MessagingSystemServiceglobal with sharing class MessagingSystemService This class is the main entry point for the Foundations Messaging System. Developers can invoke the deliverNow and deliverLater methods to send messages. Methods
deliverNowglobal static fferpcore.MessagingSystemService.DeliverNowResult deliverNow(String sendingProductDeveloperName, List<fferpcore.MessagingSystemService.MessageRequest> requests) Deliver messages synchronously. Messages will have been handled by the recipient before this method returns. This allows immediate communication and, through reply messages, results to be made available immediately. It risks exceeding limits as recipient code runs in the same execution context. As no Product Proxy is specified, it is assumed messages are being sent from the default (managed) Product Proxy. Input Parameters
Return ValueThis class always returns an fferpcore.DeliverNowResult with no content. Sample Code//Note: This sample code is for demonstration purposes only. It is not intended for //use in a production environment, is not guaranteed against defects or errors, and //is in no way optimized or streamlined. List<fferpcore.MessagingSystemService.MessageRequest> messageRequests = new List<fferpcore.MessagingSystemService.MessageRequest>(); messageRequests.add(new fferpcore.MessagingSystemService.MessageRequest('messageTypeDeveloperName', 'correlationId', 'body')); fferpcore.MessagingSystemService.deliverNow('productDeveloperName', messageRequests); // Can execute code here knowing that the messages have been handled by the subscribers. deliverNowglobal static fferpcore.MessagingSystemService.DeliverNowResult deliverNow(String productDeveloperName, String messageTypeDeveloperName, fferpcore.DataSource dataSource) This method is a convenient way to build messages using the MessageDescriptionService, then use deliverNow to deliver them. This method may avoid generating messages if it will not be possible to send them. Input Parameters
Return ValueThis class always returns an fferpcore.DeliverNowResult with no content. Sample Code//Note: This sample code is for demonstration purposes only. It is not intended for //use in a production environment, is not guaranteed against defects or errors, and //is in no way optimized or streamlined. trigger SampleTrigger on Sample__c (after insert, after update) { // Prevent an infinite loop by not sending a message in response to a message. if (!fferpcore.MessagingSystemService.isInDelivery()) { // Provide the new or updated records as a DataSource for message generation. fferpcore.DataSource dataSource = new fferpcore.TriggerDataSource(Trigger.New); // Send the messages. fferpcore.MessagingSystemService.deliverNow('ProductName', 'MessageTypeName', dataSource); // Can execute code here knowing that the messages have been handled by the subscribers. } } deliverNowglobal static fferpcore.MessagingSystemService.DeliverNowResult deliverNow(fferpcore.MessagingSystemService.Sender sender, List<fferpcore.MessagingSystemService.MessageRequest> requests) Deliver messages synchronously. Messages will have been handled by the recipient before this method returns. This allows immediate communication and, through reply messages, results to be made available immediately. It risks exceeding limits as recipient code runs in the same execution context. Input Parameters
Return ValueThis class always returns an fferpcore.DeliverNowResult with no content. Sample Code//Note: This sample code is for demonstration purposes only. It is not intended for //use in a production environment, is not guaranteed against defects or errors, and //is in no way optimized or streamlined. List<fferpcore.MessagingSystemService.MessageRequest> messageRequests = new List<fferpcore.MessagingSystemService.MessageRequest>(); messageRequests.add(new fferpcore.MessagingSystemService.MessageRequest('messageTypeDeveloperName', 'correlationId', 'body')); fferpcore.MessagingSystemService.Sender sender = new fferpcore.MessagingSystemService.Sender('ProductDevName'); fferpcore.MessagingSystemService.deliverNow(sender, messageRequests); // Can execute code here knowing that the messages have been handled by the subscribers. deliverNowglobal static fferpcore.MessagingSystemService.DeliverNowResult deliverNow(fferpcore.MessagingSystemService.Sender sender, fferpcore.MessagingSystemService.MessageTypeSpecifier messageTypeSpecifier, fferpcore.DataSource dataSource) This method is a convenient way to build messages using the MessageDescriptionService, then use deliverNow to deliver them. This method may avoid generating messages if it will not be possible to send them. Input Parameters
Return ValueThis class always returns an fferpcore.DeliverNowResult with no content. Sample Code//Note: This sample code is for demonstration purposes only. It is not intended for //use in a production environment, is not guaranteed against defects or errors, and //is in no way optimized or streamlined. trigger SampleTrigger on Sample__c (after insert, after update) { // Prevent an infinite loop by not sending a message in response to a message. if (!fferpcore.MessagingSystemService.isInDelivery()) { // Provide the new or updated records as a DataSource for message generation. fferpcore.DataSource dataSource = new fferpcore.TriggerDataSource(Trigger.New); fferpcore.MessagingSystemService.Sender sender = new fferpcore.MessagingSystemService.Sender('ProductDevName'); fferpcore.MessagingSystemService.MessageTypeSpecifier messageTypeSpecifier = new fferpcore.MessagingSystemService.Sender('Resource.Update', 'Sample__c'); // Send the messages. fferpcore.MessagingSystemService.deliverNow(sender, messageTypeSpecifier, dataSource); // Can execute code here knowing that the messages have been handled by the subscribers. } } pushVirtualRecordEventglobal static fferpcore.MessagingSystemService.DeliverNowResult pushVirtualRecordEvent(fferpcore.MessagingSystemService.VirtualRecordEventRequest request) Send the appropriate Provider and associated RecordList, to any Consumers on the specified message type. Input Parameters
Return ValueA DeliverNowResult containing correlation IDs and the number of errors and recipients. isInDeliveryglobal static Boolean isInDelivery() Return ValueTrue if a delivery is currently in progress. Sample Code//Note: This sample code is for demonstration purposes only. It is not intended for //use in a production environment, is not guaranteed against defects or errors, and //is in no way optimized or streamlined. /** * @return true if the report was successfully created */ public Boolean createExpensesReport() { //If the messaging system is still delivering messages, we shouldn't do the report as we won't have all the data we want if(fferpcore.MessagingSystemService.isInDelivery()) { return false; } //Actually create report ... } deliverLaterglobal static fferpcore.MessagingSystemService.DeliverLaterResult deliverLater(String sendingProductDeveloperName, List<fferpcore.MessagingSystemService.MessageRequest> requests) Send messages asynchronously. For each message, if the sending product is enabled to send to the message's message type, then a MessagingMessage__c is created for later delivery by the batch message delivery system. Input Parameters
Return ValueThis class always returns an fferpcore.DeliverLaterResult with no content. Sample Code//Note: This sample code is for demonstration purposes only. It is not intended for //use in a production environment, is not guaranteed against defects or errors, and //is in no way optimized or streamlined. List<fferpcore.MessagingSystemService.MessageRequest> messageRequests = new List<fferpcore.MessagingSystemService.MessageRequest>(); messageRequests.add(new fferpcore.MessagingSystemService.MessageRequest('messageTypeDeveloperName', 'correlationId', 'body')); fferpcore.MessagingSystemService.deliverLater('productDeveloperName', messageRequests); deliverLaterglobal static fferpcore.MessagingSystemService.DeliverLaterResult deliverLater(String productDeveloperName, String messageTypeDeveloperName, fferpcore.DataSource dataSource) Convenience method to build messages using the MessageDescriptionService, then use deliverLater to deliver them. This method may avoid generating messages if it will not be possible to send them. Input Parameters
Return ValueThis class always returns an fferpcore.DeliverLaterResult with no content. Sample Code//Note: This sample code is for demonstration purposes only. It is not intended for //use in a production environment, is not guaranteed against defects or errors, and //is in no way optimized or streamlined. trigger SampleTrigger on Sample__c (after insert, after update) { // Prevent an infinite loop by not sending a message in response to a message. if (!fferpcore.MessagingSystemService.isInDelivery()) { // Provide the new or updated records as a DataSource for message generation. fferpcore.DataSource dataSource = new fferpcore.TriggerDataSource(Trigger.New); // Send the messages. They will be saved to the DB now. The subscription handlers will process them later. fferpcore.MessagingSystemService.deliverLater('ProductName', 'MessageTypeName', dataSource); } } deliverLaterglobal static fferpcore.MessagingSystemService.DeliverLaterResult deliverLater(fferpcore.MessagingSystemService.Sender sender, List<fferpcore.MessagingSystemService.MessageRequest> requests) Send messages asynchronously. For each message, if the sending product is enabled to send to the message's message type, then a MessagingMessage__c is created for later delivery by the batch message delivery system. Input Parameters
Return ValueThis class always returns an fferpcore.DeliverLaterResult with no content. Sample Code//Note: This sample code is for demonstration purposes only. It is not intended for //use in a production environment, is not guaranteed against defects or errors, and //is in no way optimized or streamlined. List<fferpcore.MessagingSystemService.MessageRequest> messageRequests = new List<fferpcore.MessagingSystemService.MessageRequest>(); messageRequests.add(new fferpcore.MessagingSystemService.MessageRequest('messageTypeDeveloperName', 'correlationId', 'body')); fferpcore.MessagingSystemService.Sender sender = new fferpcore.MessagingSystemService.Sender('ProductDevName'); fferpcore.MessagingSystemService.deliverLater(sender, messageRequests); deliverLaterglobal static fferpcore.MessagingSystemService.DeliverLaterResult deliverLater(fferpcore.MessagingSystemService.Sender sender, fferpcore.MessagingSystemService.MessageTypeSpecifier messageTypeSpecifier, fferpcore.DataSource dataSource) Convenience method to build messages using the MessageDescriptionService, then use deliverLater to deliver them. This method may avoid generating messages if it will not be possible to send them. Input Parameters
Return ValueThis class always returns an fferpcore.DeliverLaterResult with no content. Sample Code//Note: This sample code is for demonstration purposes only. It is not intended for //use in a production environment, is not guaranteed against defects or errors, and //is in no way optimized or streamlined. trigger SampleTrigger on Sample__c (after insert, after update) { // Prevent an infinite loop by not sending a message in response to a message. if (!fferpcore.MessagingSystemService.isInDelivery()) { // Provide the new or updated records as a DataSource for message generation. fferpcore.DataSource dataSource = new fferpcore.TriggerDataSource(Trigger.New); fferpcore.MessagingSystemService.Sender sender = new fferpcore.MessagingSystemService.Sender('ProductDevName'); fferpcore.MessagingSystemService.MessageTypeSpecifier messageTypeSpecifier = new fferpcore.MessagingSystemService.Sender('Resource.Update', 'Sample__c'); // Send the messages. They will be saved to the DB now. The subscription handlers will process them later. fferpcore.MessagingSystemService.deliverLater(sender, messageTypeSpecifier, dataSource); } } deliverLaterUsingBatchglobal static fferpcore.MessagingSystemService.DeliverLaterResult deliverLaterUsingBatch(fferpcore.MessagingSystemService.Sender sender, fferpcore.MessagingSystemService.MessageTypeSpecifier specifier, SObjectType objectType, String queryCondition, Integer scopeSize) Create a batch job to asynchronously queue a large volume of messages for future delivery. Input Parameters
Return ValueThis class always returns an fferpcore.DeliverLaterResult with no content. newResponseCapturingScopeglobal static fferpcore.Disposable newResponseCapturingScope(fferpcore.MessagingSystemService.ResponseCapturingRequest request) Enables synchronous responses to messages to be captured and processed in a single delivery. Deliveries for the specified subscriptions are collected for processing when the scope is disposed of. This enables more efficient processing when a synchronous request generates synchronous responses from several recipients. If a response capturing scope is not used, then each set of responses to the original request are processed separately. Each set of responses then generates their own SOQL and DML overhead. Input Parameters
Sample Code//Note: This sample code is for demonstration purposes only. It is not intended for //use in a production environment, is not guaranteed against defects or errors, and //is in no way optimized or streamlined. /** * Sends a message requesting voting responses from several recipients. * Collects the responses into a single delivery for efficient processing. */ global class VotingExample { private static final fferpcore.MessagingSystemService.Sender MYSELF = new fferpcore.MessagingSystemService.Sender('ExampleProduct'); private static final fferpcore.MessagingSystemService.MessageTypeSpecifier REQUEST_MESSAGE_TYPE = new fferpcore.MessagingSystemService.MessageTypeSpecifier('Samples.Voting.Request'); private static final fferpcore.MessagingSystemService.MessageTypeSpecifier RESPONSE_MESSAGE_TYPE = new fferpcore.MessagingSystemService.MessageTypeSpecifier('Samples.Voting.Response'); /** * Request that a vote be taken. Tally the responses and create a record. */ public void collectVotes(String question) { // Use of a pre-initialised handler allows a result to be captured for the calling method. VoteHandler handler = new VoteHandler(question); fferpcore.Disposable scope = fferpcore.MessagingSystemService.newResponseCapturingScope( new fferpcore.MessagingSystemService.ResponseCapturingRequest() .forSubscription(MYSELF, RESPONSE_MESSAGE_TYPE, handler) ); try { fferpcore.MessagingSystemService.deliverNow(MYSELF, new List<fferpcore.MessagingSystemService.MessageRequest>{ new fferpcore.MessagingSystemService.MessageRequest(REQUEST_MESSAGE_TYPE, null, question) }); } finally { // Responses are processed here. The handler's onMessages method will only // be called once. scope.dispose(); } } /** * The message handler to use for the Response messages. */ global class VoteHandler implements fferpcore.MessageHandler { private final String m_question; /** * This constructor is used by FinancialForce ERP Core when the handler receives a message * outside the capturing scope. */ global VoteHandler() { m_question = 'No question was asked!'; } /** * This constructor is used in the collectVotes method above. */ public VoteHandler(String question) { m_question = question; } /** * Implementation of the onMessages method from the fferpcore.MessageHandler interface. */ global void onMessages(fferpcore.HandleMessagesRequest request) { Integer yes = 0, no = 0, spoiled = 0; for(fferpcore.DeliveredMessage message : request.getMessages()) { String response = message.getBody(); if(response == 'Yes') { yes++; } else if(response == 'No') { no++; } else { spoiled++; message.respondError(new fferpcore.ErpErrorBody('Vote was not recognised.')); } } insert new VotingResult__c( Question__c = m_question, Yes__c = yes, No__c = no, Spoiled__c = spoiled ); } } } isInBatchDeliveryglobal static Boolean isInBatchDelivery() Return ValueTrue if a batch job is currently in progress. Sample Code//Note: This sample code is for demonstration purposes only. It is not intended for //use in a production environment, is not guaranteed against defects or errors, and //is in no way optimized or streamlined. /** * A MessageHandler's onMessages method will be invoked when the subscription it is associated to * receives messages from a publication of the same message type. */ public class ExampleHandler implements fferpcore.MessageHandler { public void onMessages(fferpcore.HandleMessagesRequest request) { for(fferpcore.DeliveredMessage message : request.getMessages()) { s_deliveredMessages.add(message); message.respondSuccess(); if(fferpcore.MessagingSystemService.isInBatchDelivery()) { //Code when this handler receiving messages is in batch } } } } isDormantglobal static Boolean isDormant() Return ValueTrue if the current endpoints would cause no new messages to be sent. Dormant does not prevent delivery. of existing messages. Sample Code//Note: This sample code is for demonstration purposes only. It is not intended for //use in a production environment, is not guaranteed against defects or errors, and //is in no way optimized or streamlined. if (!fferpcore.MessagingSystemService.isDormant()) { //Create messages and requests. } canDeliverglobal static Map<fferpcore.MessagingSystemService.MessageTypeSpecifier, Boolean> canDeliver(fferpcore.MessagingSystemService.Sender sender, Set<fferpcore.MessagingSystemService.MessageTypeSpecifier> specifiers) Determines whether delivery can take place for the sender and message type specifiers provided. Input Parameters
Return ValueA map of each message type specifier with a boolean indicating whether delivery is possible for that message type specifier. fferpcore.MessagingSystemService.VirtualRecordEventRequestglobal class VirtualRecordEventRequest Data necessary for the pushVirtualRecordEvent method. Methods
VirtualRecordEventRequestglobal VirtualRecordEventRequest(fferpcore.MessagingSystemService.Sender sender, fferpcore.MessagingSystemService.MessageTypeSpecifier messageType, Set<String> virtualRecordIds) Construct a VirtualRecordEventRequest. Input Parameters
withSharingModelglobal fferpcore.MessagingSystemService.VirtualRecordEventRequest withSharingModel(SharingModel sharingModel) Specify the sharing policy to be used by the resulting Provider. Input Parameters
getSharingModelglobal SharingModel getSharingModel() Return ValueThe sharing policy to be used by the resulting Provider. withSourceObjectErrorListenerglobal fferpcore.MessagingSystemService.VirtualRecordEventRequest withSourceObjectErrorListener(fferpcore.VirtualDataObject.ErrorListener errorListener) Specify an ErrorListener to be notified if any errors are added to the source Records. Input Parameters
getSourceObjectErrorListenersglobal List<fferpcore.VirtualDataObject.ErrorListener> getSourceObjectErrorListeners() Return ValueThe ErrorListeners to be notified when errors are added to the source Records. getSenderglobal fferpcore.MessagingSystemService.Sender getSender() Return ValueThe product responsible for sending the data. getMessageTypeSpecifierglobal fferpcore.MessagingSystemService.MessageTypeSpecifier getMessageTypeSpecifier() Return ValueThe message type on which to send the data. getVirtualRecordIdsglobal Set<String> getVirtualRecordIds() Return ValueThe IDs of the Records to obtain using the Provider. fferpcore.MessagingSystemService.ResponseCapturingRequestglobal class ResponseCapturingRequest Contains a request to capture synchronous responses so that they can be processed in a single delivery. Methods
forSubscriptionglobal fferpcore.MessagingSystemService.ResponseCapturingRequest forSubscription(fferpcore.EndpointKey endpoint) Captures responses for the given subscription using its preconfigured handler. Return ValueThe ResponseCapturingRequest. This enables other methods to be invoked. forSubscriptionglobal fferpcore.MessagingSystemService.ResponseCapturingRequest forSubscription(fferpcore.EndpointKey endpoint, fferpcore.MessageHandler handler) Captures responses for the given subscription using a preinitialized handler. Return ValueThe ResponseCapturingRequest. This enables other methods to be invoked. forSubscriptionglobal fferpcore.MessagingSystemService.ResponseCapturingRequest forSubscription(fferpcore.MessagingSystemService.Sender sender, fferpcore.MessagingSystemService.MessageTypeSpecifier messageType) Captures responses for the given subscription using its preconfigured handler. Input Parameters
Return ValueThe ResponseCapturingRequest. This enables other methods to be invoked. forSubscriptionglobal fferpcore.MessagingSystemService.ResponseCapturingRequest forSubscription(fferpcore.MessagingSystemService.Sender sender, fferpcore.MessagingSystemService.MessageTypeSpecifier messageType, fferpcore.MessageHandler handler) Captures responses for the given subscription using a preinitialized handler. Input Parameters
Return ValueThe ResponseCapturingRequest. This enables other methods to be invoked. createScopeglobal fferpcore.Disposable createScope() Provides a convenient way to call MessagingSystemService.newResponseCapturingScope() with this request. Return ValueThe created capturing scope. Sample Code//Note: This sample code is for demonstration purposes only. It is not intended for //use in a production environment, is not guaranteed against defects or errors, and //is in no way optimized or streamlined. fferpcore.Disposable scope = new fferpcore.MessagingSystemService.ResponseCapturingRequest() .forSubscription(MYSELF, RESPONSE_MESSAGE_TYPE, handler) .createScope(); fferpcore.MessagingSystemService.MessageRequestglobal virtual class MessageRequest A request to send a Message. Methods
MessageRequestglobal MessageRequest(String messageTypeDeveloperName, String correlationId, String body) Input Parameters
MessageRequestglobal MessageRequest(fferpcore.MessagingSystemService.MessageTypeSpecifier messageTypeSpecifier, String correlationId, String body) Input Parameters
getMessageTypeDeveloperNameglobal String getMessageTypeDeveloperName() Return ValueThe developer name of the message type associated with this request. getMessageTypeSpecifierglobal virtual fferpcore.MessagingSystemService.MessageTypeSpecifier getMessageTypeSpecifier() Return ValueThe qualified message type of this request. getCorrelationIdglobal String getCorrelationId() Return ValueThe correlation Id associated with this request. equalsglobal Boolean equals(Object obj) This compares all the values between the method caller and the object provided. This ensures that the two objects are of the same type and that all the data on the object is identical. Input Parameters
hashcodeglobal Integer hashcode() Return ValueA hashcode based on all the information on the object. fferpcore.MessagingSystemService.DeliverNowResultglobal class DeliverNowResult A result which contains the results of the messages sent. Methods
DeliverNowResultglobal DeliverNowResult() Default constructor provided to support legacy test code in client software. DeliverNowResultglobal DeliverNowResult(List<fferpcore.MessagingSystemService.SynchronousMessageResult> results) Constructs a DeliverNowResult. Input Parameters
getResultsByCorrelationglobal Map<String, fferpcore.MessagingSystemService.SynchronousMessageResult> getResultsByCorrelation() Return ValueThe delivery results for each message keyed on correlation ID. fferpcore.MessagingSystemService.SynchronousMessageResultglobal interface SynchronousMessageResult The result of a deliver now request for a message. Methods
getRecipientCountInteger getRecipientCount() Return ValueThe number of recipients of the message. This count includes successful deliveries, errors and deferred. getDeferredCountInteger getDeferredCount() Return ValueThe number of deliveries that have been deferred. This count includes messages delivered by a batch process and by the capturing scope mechanism. fferpcore.MessagingSystemService.DeliverLaterResultglobal class DeliverLaterResult A currently empty result allows us to add result information later while keeping within Salesforce's upgrade restrictions. fferpcore.MessagingSystemService.Senderglobal class Sender A class that wraps up information about who is sending the message. It combines a Product and a ProductProxy. Methods
Senderglobal Sender(String productDeveloperName) Creates a Sender for the specified product and the Managed Product Proxy. This method is a convenience for calling MessagingSystemService.Sender(product, ProductProxies.MANAGED_PROXY_DEVELOPER_NAME). Input Parameters
Senderglobal Sender(String productDeveloperName, String productProxyDeveloperName) Creates a Sender from the specified product and proxy. Input Parameters
withForceSendglobal fferpcore.MessagingSystemService.Sender withForceSend(Boolean forceSend) Specifies whether this sender ignores the process builder scope and flag. Input Parameters
Return ValueThe Sender instance. This enables further methods to be invoked. getProductDeveloperNameglobal String getProductDeveloperName() Return ValueReturns the developerName of the Product. getProductProxyDeveloperNameglobal String getProductProxyDeveloperName() Return ValueThe developerName of the proxy that the product is sending on behalf of. getForceSendglobal Boolean getForceSend() Return ValueA boolean value that indicates whether this sender ignores the process builder scope and flag. fferpcore.MessagingSystemService.MessageTypeSpecifierglobal class MessageTypeSpecifier A class that contains information about the type of message sent in a particular request. It contains the message type, and also a identifier. A product/proxy can have different publications for the same message type if they have different identifiers. This class is used to identify the publication a product/proxy wishes to send on. Methods
MessageTypeSpecifierglobal MessageTypeSpecifier(String messageTypeDeveloperName, String identifier) Creates a MessageTypeSpecifier from the supplied MessageType and Identifier Input Parameters
MessageTypeSpecifierglobal MessageTypeSpecifier(String messageTypeDeveloperName) Creates a MessageTypeSpecifier from the supplied MessageType and no Identifier Input Parameters
getMessageTypeDeveloperNameglobal String getMessageTypeDeveloperName() Return ValueThe developerName of the messageType. getIdentifierglobal String getIdentifier() Return ValueThe identifier used when this object was constructed. |