Foundations Apex API Developer Reference

fferpcore.LinkingMessageHandler

global with sharing class LinkingMessageHandler

A fferpcore.LinkingMessageHandler structure.

Methods

LinkingMessageHandler

global LinkingMessageHandler(Schema.SObjectType recipientObject, fferpcore.LinkingCorrelationStrategy correlation, fferpcore.LinkingMessageToObjectMarshaller marshaller, String linkDeveloperName)

The constructor used to create a fferpcore.LinkingMessageHandler object. This constructor is used to define what SObject type is to be created, how it will be linked together and where the link comes from.

Input Parameters

Name Type Description
recipientObject Schema.SObjectType The SObject type that will be created.
correlation fferpcore.LinkingCorrelationStrategy An object which will be used to access records via a correlation field.
marshaller fferpcore.LinkingMessageToObjectMarshaller An object to apply given messages to specific SObjects with any additional fields.
linkDeveloperName String A name to specify where the message was 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.

//This is the subscribers handler class
global class HCMUpdateResourceHandler implements fferpcore.MessageHandler
{
    public static final String LINK_DEVELOPER_NAME = 'HCM';
    public static final String PRODUCT_DEVELOPER_NAME = 'HCM';
    public static final String RESOURCE_LINK_CONTROL_MESSAGE_TYPE = 'Resource.LinkControl';

    public void onMessages(fferpcore.HandleMessagesRequest request)
    {
        List<fferpcore.DeliveredMessage> messages = request.getMessages();

        fferpcore.SubscriptionDescription description = 
            fferpcore.SubscriptionDescriptionService.getDescription(PRODUCT_DEVELOPER_NAME, UpdateResourceMessage.TYPE_NAME).getDescription();

        fferpcore.LinkingCorrelationStrategy correlation = 
            new fferpcore.SimpleLinkingCorrelationStrategy(HCMFakeWorker__c.EmployeeId__c);

        fferpcore.LinkingMessageHandler linkingMessageHandler = 
            new fferpcore.LinkingMessageHandler(HCMFakeWorker__c.SObjectType, correlation, description, LINK_DEVELOPER_NAME);

        fferpcore.LinkingMessageHandlerResult result = linkingMessageHandler.onMessages(messages);
        
        fferpcore.MessagingSystemService.deliverNow(PRODUCT_DEVELOPER_NAME, result.createMessageRequestsFor(RESOURCE_LINK_CONTROL_MESSAGE_TYPE));
    }
}

withAllowCreate

global fferpcore.LinkingMessageHandler withAllowCreate(Boolean value)

Determines whether this handler is able to create new records. If true, this handler creates a new record if the correlation strategy does not return a record. If false, this handler reports an error if the correlation strategy does not return a record. The correlation strategy can create and return new records regardless of this setting. The default value is true.

onMessages

global fferpcore.LinkingMessageHandlerResult onMessages(List<fferpcore.DeliveredMessage> messages)

This method takes a list of delivered messages and selects a list of all the correlation IDs from those messages. With this list, it then selects a list of all the objects with the correlation IDs of the specified type and, if they exist, tries to update them. Otherwise, it tries to create a new object. When this has been done, it returns information about the creation and updating of objects.

Input Parameters

Name Type Description
messages List<fferpcore.DeliveredMessage> The list of messages we want to use to create or update objects.

Return Value

This service returns a LinkingMessageHandlerResult 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.

//This is the subscribers handler class
global class HCMUpdateResourceHandler implements fferpcore.MessageHandler
{
    public static final String LINK_DEVELOPER_NAME = 'HCM';
    public static final String PRODUCT_DEVELOPER_NAME = 'HCM';
    public static final String RESOURCE_LINK_CONTROL_MESSAGE_TYPE = 'Resource.LinkControl';

    public void onMessages(fferpcore.HandleMessagesRequest request)
    {
        List<fferpcore.DeliveredMessage> messages = request.getMessages();

        fferpcore.SubscriptionDescription description = 
            fferpcore.SubscriptionDescriptionService.getDescription(PRODUCT_DEVELOPER_NAME, UpdateResourceMessage.TYPE_NAME).getDescription();

        fferpcore.LinkingCorrelationStrategy correlation = 
            new fferpcore.SimpleLinkingCorrelationStrategy(HCMFakeWorker__c.EmployeeId__c);

        fferpcore.LinkingMessageHandler linkingMessageHandler = 
            new fferpcore.LinkingMessageHandler(HCMFakeWorker__c.SObjectType, correlation, description, LINK_DEVELOPER_NAME);

        fferpcore.LinkingMessageHandlerResult result = linkingMessageHandler.onMessages(messages);
        
        fferpcore.MessagingSystemService.deliverNow(PRODUCT_DEVELOPER_NAME, result.createMessageRequestsFor(RESOURCE_LINK_CONTROL_MESSAGE_TYPE));
    }
}
© Copyright 2009–2022 FinancialForce.com, inc. All rights reserved. Various trademarks held by their respective owners.