ERP Core API Developer Reference

fferpcore.MessagingSystemService

global with sharing class MessagingSystemService

This class is the main entry point for the ERP Messaging System. Developers can invoke the deliverNow and deliverLater methods to send messages.

Methods

deliverNow

global 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

Name Type Description
sendingProductDeveloperName String The name of the product that is sending the messages.
requests List<fferpcore.MessagingSystemService.MessageRequest> The message requests

Return Value

This class always returns a 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.

deliverNow

global 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

Name Type Description
productDeveloperName String The name of the product that is sending the messages, as used with fferpcore.RegistrationService.
messageTypeDeveloperName String The developer name of the Message Type to generate messages for.
dataSource fferpcore.DataSource Input data to use to generate the messages.

Return Value

This class always returns a 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.
    }
}

deliverNow

global 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

Name Type Description
sender fferpcore.MessagingSystemService.Sender The Product and ProductProxy publishing these messages.
requests List<fferpcore.MessagingSystemService.MessageRequest> The message requests.

Return Value

This class always returns a 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.

deliverNow

global 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

Name Type Description
sender fferpcore.MessagingSystemService.Sender The Product and ProductProxy publishing these messages.
messageTypeSpecifier fferpcore.MessagingSystemService.MessageTypeSpecifier The MessageType and Identifier we are sending.
dataSource fferpcore.DataSource Input data to use to generate the messages.

Return Value

This class always returns a 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.
    }
}

isInDelivery

global static Boolean isInDelivery()

Return Value

True 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
    ...
}

deliverLater

global 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

Name Type Description
sendingProductDeveloperName String The name of the product that is sending the messages.
requests List<fferpcore.MessagingSystemService.MessageRequest> The message requests.

Return Value

This class always returns a 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);

deliverLater

global 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

Name Type Description
productDeveloperName String The name of the product that is sending the messages, as used with fferpcore.RegistrationService.
messageTypeDeveloperName String The developer name of the Message Type to generate messages for.
dataSource fferpcore.DataSource Input data to use to generate the messages.

Return Value

This class always returns a 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);
    }
}

deliverLater

global 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

Name Type Description
sender fferpcore.MessagingSystemService.Sender The Product and ProductProxy publishing these messages.
requests List<fferpcore.MessagingSystemService.MessageRequest> The message requests.

Return Value

This class always returns a 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);

deliverLater

global 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

Name Type Description
sender fferpcore.MessagingSystemService.Sender The Product and ProductProxy publishing these messages.
messageTypeSpecifier fferpcore.MessagingSystemService.MessageTypeSpecifier The MessageType and Identifier we are sending.
dataSource fferpcore.DataSource Input data to use to generate the messages.

Return Value

This class always returns a 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);
    }
}

isInBatchDelivery

global static Boolean isInBatchDelivery()

Return Value

True 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
            }
        }
    }
}

isDormant

global static Boolean isDormant()

Return Value

True 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.
    
}

fferpcore.MessagingSystemService.MessageRequest

global virtual class MessageRequest

A request to send a Message.

Methods

MessageRequest

global MessageRequest(String messageTypeDeveloperName, String correlationId, String body)

Input Parameters

Name Type Description
messageTypeDeveloperName String The message type to send this message to.
correlationId String A string that identifies related messages.
body String The message content.

MessageRequest

global MessageRequest(fferpcore.MessagingSystemService.MessageTypeSpecifier messageTypeSpecifier, String correlationId, String body)

Input Parameters

Name Type Description
messageTypeSpecifier fferpcore.MessagingSystemService.MessageTypeSpecifier An object that combines the MessageType and a Identifier
correlationId String A string that identifies related messages.
body String The message content.

getMessageTypeDeveloperName

global String getMessageTypeDeveloperName()

Return Value

The developer name of the message type associated with this request.

getMessageTypeSpecifier

global virtual fferpcore.MessagingSystemService.MessageTypeSpecifier getMessageTypeSpecifier()

Return Value

The qualified message type of this request.

getCorrelationId

global String getCorrelationId()

Return Value

The correlation Id associated with this request.

getBody

global String getBody()

Return Value

The message body associated with this request.

equals

global 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

Name Type Description
obj Object The object we want to compare against.

hashcode

global Integer hashcode()

Return Value

A hashcode based on all the information on the object.

fferpcore.MessagingSystemService.DeliverNowResult

global class DeliverNowResult

A currently empty result allows us to add result information later while keeping within Salesforce's upgrade restrictions.

fferpcore.MessagingSystemService.DeliverLaterResult

global class DeliverLaterResult

A currently empty result allows us to add result information later while keeping within Salesforce's upgrade restrictions.

fferpcore.MessagingSystemService.Sender

global class Sender

A class that wraps up information about who is sending the message. It combines a Product and a ProductProxy.

Methods

Sender

global 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

Name Type Description
productDeveloperName String The developerName of the Product we are sending from.

Sender

global Sender(String productDeveloperName, String productProxyDeveloperName)

Creates a Sender from the specified product and proxy.

Input Parameters

Name Type Description
productDeveloperName String The developerName of the Product we are sending from.
productProxyDeveloperName String The developerName of the ProductProxy we are sending from.

getProductDeveloperName

global String getProductDeveloperName()

Return Value

Returns the developerName of the Product.

getProductProxyDeveloperName

global String getProductProxyDeveloperName()

Return Value

The developerName of the proxy that the product is sending on behalf of.

fferpcore.MessagingSystemService.MessageTypeSpecifier

global 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

MessageTypeSpecifier

global MessageTypeSpecifier(String messageTypeDeveloperName, String identifier)

Creates a MessageTypeSpecifier from the supplied MessageType and Identifier

Input Parameters

Name Type Description
messageTypeDeveloperName String The developerName of a messageType.
identifier String A string that provides extra information to identify the publication we wish to use.

MessageTypeSpecifier

global MessageTypeSpecifier(String messageTypeDeveloperName)

Creates a MessageTypeSpecifier from the supplied MessageType and no Identifier

Input Parameters

Name Type Description
messageTypeDeveloperName String The developerName of a messageType.

getMessageTypeDeveloperName

global String getMessageTypeDeveloperName()

Return Value

The developerName of the messageType.

getIdentifier

global String getIdentifier()

Return Value

The identifier used when this object was constructed.