Foundations Apex API Developer Reference

fferpcore.DeliveredMessage

global abstract class DeliveredMessage implements Navigable

A message delivery, with callbacks to respond.

This class implements the following interfaces:

Methods

getCorrelationId

global abstract String getCorrelationId()

Return Value

A string identifying the data that comprises the source of the message, for example, the Id of an SObject. It should be a field with unique values to ensure it uniquely identifies the data source object.

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.

/**
 * Method to group messages together based on the correlationId. 
 */
public Map<String, List<fferpcore.DeliveredMessage>> getMessagesByCorrelationId(List<fferpcore.DeliveredMessage> messages)
{
    Map<String, List<fferpcore.DeliveredMessage>> messagesByCorrelationId = new Map<String, List<fferpcore.DeliveredMessage>>();
 
    for(fferpcore.DeliveredMessage message : messages)
    {
        String correlationId = message.getCorrelationId();
        List<fferpcore.DeliveredMessage> correlationIdMessages = messagesByCorrelationId.get(correlationId);

        if(correlationIdMessages == null)
        {
            correlationIdMessages = new List<fferpcore.DeliveredMessage>();
            messagesByCorrelationId.put(correlationId, correlationIdMessages);
        }

        correlationIdMessages.add(message);
    }

    return messagesByCorrelationId;
}

getBody

global abstract String getBody()

Return Value

A JSON serialized string containing the message body.

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.DeliveredMessage message = getMessage(); //We are handling this message
Map<String, Object> body = (Map<String, Object>) JSON.deserializeUntyped(message.getBody());
String email = (String) body.get('["Email"]');
//Do something with the email.

hasResponse

global abstract Boolean hasResponse()

Return Value

A boolean indicating whether or not the message has been successfully received.

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.

/**
 * Look through the messages in the request and deal with any errors.
 */
private void checkForErrors(fferpcore.HandleMessagesRequest request)
{
    for(fferpcore.DeliveredMessage message : request.getMessages())
    {
        if(!message.hasResponse())
        {
            message.respondError(new fferpcore.ErpErrorBody("An error has occurred"));
        }
    }
}

respondSuccess

global abstract void respondSuccess()

This method is called to indicate a message was handled successfully and changes have been committed to the database. Even if an exception is thrown after this method is called, the message will remain successful.

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.DeliveredMessage message = getMessage(); //We are handling this message
Map<String, Object> body = (Map<String, Object>) JSON.deserializeUntyped(message.getBody());
String email = (String) body.get('["Email"]'); //Do something with the email.
message.respondSuccess();    

respondError

global abstract void respondError(fferpcore.ErpErrorBody body)

This method can be called in the event of a validation error or other error handling the messsage. It stores details of the error on the message.

Input Parameters

Name Type Description
body fferpcore.ErpErrorBody Contains information on the error affecting this message.

Sample Data

fferpcore.ErpErrorBody body: new fferpcore.ErpErrorBody("Error");

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.

/**
 * Look through the messages in the request and deal with any errors.
 */
private void checkForErrors(fferpcore.HandleMessagesRequest request)
{
    for(fferpcore.DeliveredMessage message : request.getMessages())
    {
        if(!message.hasResponse())
        {
            message.respondError(new fferpcore.ErpErrorBody("An error has occurred"));
        }
    }
}

respondFiltered

global virtual void respondFiltered()

This method can be called in the event of a message being ignored due to a filter.

getMessageType

global virtual String getMessageType()

Return Value

The DeveloperName__c from the messageType of this message.

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 message handler that calls different code based on the messageType.
 */
global class MyMessageHandlerImpl implements fferpcore.MessageHandler
{
    global void onMessages(fferpcore.HandleMessagesRequest request)
    {
        // This handler uses handler data for configuration. The handler data is the expected string.
        String expectedContent = handlerData.get('ExpectedContent');
   
        for(fferpcore.DeliveredMessage message : request.getMessages())
        {
            if(message.getMessageType() == 'Resource.Update.SkillUpdate')
            {
                handleSkillMessage(message);
            }
            else if (message.getMessageType() == 'Resource.Update.NewAddress')
            {
                handleNewAddressMessage(message);
            }
            else
            {
                message.respondError(new fferpcore.ErpErrorBody('Unexpected message type'));
            }
        }
    }

    private void handleSkillMessage(fferpcore.DeliveredMessage message)
    {
        ...
    }

    private void handleNewAddressMessage(fferpcore.DeliveredMessage message)
    {
        ...
    }
}

getDeserializedBody

global virtual Object getDeserializedBody()

Assuming the message is JSON, return its deserializedUntyped form. This allows caching of the result.

Return Value

The result of calling JSON.deserializeUntyped on the message body.

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.DeliveredMessage message = getMessage(); //We are handling this message
Map<String, Object> body = (Map<String, Object>) message.getDeserializedBody();
String email = (String) body.get('["Email"]'); //Do something with the email.     

getValue

global virtual Object getValue(fferpcore.Path path)

Locates a specific value in the message at the given path.

Input Parameters

Name Type Description
path fferpcore.Path The location of the value in the message.

Return Value

The specific value at the given path.

© Copyright 2009–2022 FinancialForce.com, inc. All rights reserved. Various trademarks held by their respective owners.