fferpcore.DeliveredMessageglobal inherited sharing abstract class DeliveredMessage implements Navigable A message delivery, with callbacks to respond. This class implements the following interfaces: Methods
getCorrelationIdglobal abstract String getCorrelationId() Return ValueA 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; } getBodyglobal abstract String getBody() Return ValueA 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. hasResponseglobal abstract Boolean hasResponse() Return ValueA 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")); } } } respondSuccessglobal 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(); respondErrorglobal 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
Sample Datafferpcore.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")); } } } respondFilteredglobal virtual void respondFiltered() This method can be called in the event of a message being ignored due to a filter. getMessageTypeglobal virtual String getMessageType() Return ValueThe 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) { ... } } getDeserializedBodyglobal virtual Object getDeserializedBody() Assuming the message is JSON, return its deserializedUntyped form. This allows caching of the result. Return ValueThe 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. getValueglobal virtual Object getValue(fferpcore.Path path) Locates a specific value in the message at the given path. Input Parameters
Return ValueThe specific value at the given path. |