Foundations Apex API Developer Reference

fferpcore.ProcessMessage

global with sharing class ProcessMessage

fferpcore.Message used for requests and responses in a two phase commit process.

Properties

Name Type Description
PROCESS_STATE_PREPARING String The state returned when the a new ProcessMessage is created.
PROCESS_STATE_PENDING String The state returned when the a ProcessMessage is awaiting replies.
PROCESS_STATE_FAILIRE String The state returned when the a ProcessMessage has failed.
PROCESS_STATE_COMPLETE String The state returned when the a ProcessMessage has completed.
MESSAGE_KEY_ID String The message key for the subject of the message.
MESSAGE_KEY_TOKEN String The message key for the process token of the message.
MESSAGE_KEY_STATUS String The message key for the status of the message.
MESSAGE_KEY_MESSAGE String The message key for the service message of the message.
MESSAGE_KEY_DATA String The message key for the additional data of the message.
MESSAGE_KEY_REPLY_TO String The message key for the receiver of the message.
MESSAGE_KEY_MESSAGE_VERSION String The message key for the version of the message.
CONTEXT_KEY_TOKEN String The context key for the process token from the fferpcore.DataSource.
CONTEXT_KEY_STATUS String The context key for the status from the fferpcore.DataSource.
CONTEXT_KEY_MESSAGE String The context key for the message from the fferpcore.DataSource.
CONTEXT_KEY_DATA String The context key for the additional data from the fferpcore.DataSource.

Methods

createToken

global static String createToken()

Creates a new 36 character token for use in a new process. The token is derived from the current time and current user. This is has reasonable likelihood of being unique.

forNewProcess

global static fferpcore.ProcessMessage forNewProcess(Id recordId, String processToken, String replyTo)

Creates a Process fferpcore.Message for a new process.

Input Parameters

Name Type Description
recordId Id The ID of the record that is the subject of the process.
processToken String The token to identify this process attempt.
replyTo String The message type developer name on which recipients should reply.

Return Value

The generated ProcessMessage

newCompleteMessage

global static fferpcore.ProcessMessage newCompleteMessage(Id recordId, String processToken, Map<String, Object> userData)

Creates a Process fferpcore.Message to signify that a process is complete.

Input Parameters

Name Type Description
recordId Id The ID of the record that is the subject of the process.
processToken String The token to identify this process attempt.
userData Map<String, Object> Data that will be included in the "data" part of the message.

Return Value

The generated ProcessMessage

fromMessage

global static fferpcore.ProcessMessage fromMessage(Map<String, Object> messageBody)

Deserializes a fferpcore.ProcessMessage from a message body that has already been deserialized using JSON.deserializeUntyped(). See DeliveredMessage.getDeserializedBody().

Input Parameters

Name Type Description
messageBody Map<String, Object> The message body in Map form.

Return Value

The deserialized ProcessMessage.

getMessageVersion

global Integer getMessageVersion()

Return Value

The Process Message Version of this messsage.

createReply

global fferpcore.ProcessMessage createReply(String responseState, String message)

Creates a reply to the message with the state and message provided.

Input Parameters

Name Type Description
responseState String The response status code.
message String Additional message text for the end user.

Return Value

The generated ProcessMessage.

serialize

global String serialize()

Serializes the message for delivery over Foundations.

getSubjectId

global Id getSubjectId()

Return Value

The ID of the record that is the subject of this process message.

getProcessToken

global String getProcessToken()

Return Value

The token that identifies this attempt at the process.

getStatus

global String getStatus()

Return Value

The process status code.

setStatus

global void setStatus(String status)

Input Parameters

Name Type Description
status String The process status code.

getMessage

global String getMessage()

Return Value

The optional message associated with the status.

setMessage

global void setMessage(String message)

Input Parameters

Name Type Description
message String The optional message associated with the status.

getData

global Map<String, Object> getData()

Return Value

The map of user data values that will be included with the message.

getReplyTo

global String getReplyTo()

Return Value

The message type developer name on which the process initiator expects to receive replies.

isComplete

global Boolean isComplete()

Return Value

True of the process status is PROCES_STATE_COMPLETE

isPending

global Boolean isPending()

Return Value

True of the process status is PROCES_STATE_PENDING

fferpcore.ProcessMessage.MessageDescriptionBuilder

global inherited sharing class MessageDescriptionBuilder

Builder of fferpcore.MessageDescription for a Process fferpcore.Message Publication.

Methods

MessageDescriptionBuilder

global MessageDescriptionBuilder(SObjectType objectType, SObjectField correlationField)

Constructs a MessageDescriptionBuilder.

Input Parameters

Name Type Description
objectType SObjectType The type of SObject that will be the subject of the process messages.
correlationField SObjectField The correlation field for the messages.

withReplyToMessageType

global fferpcore.ProcessMessage.MessageDescriptionBuilder withReplyToMessageType(String replyTo)

Specifies a value for the Process fferpcore.Message Reply To message key. Used by the initiator of the process.

Input Parameters

Name Type Description
replyTo String The Message Type Developer Name on which the process initiator is expecting responses.

Return Value

This MessageDescriptionBuilder to support fluent coding style.

withMessageVersion

global fferpcore.ProcessMessage.MessageDescriptionBuilder withMessageVersion(Integer version)

Specifies a value for the Process fferpcore.Message Version message key.

Input Parameters

Name Type Description
version Integer The version of the Process Message protocol used by this publication.

Return Value

This MessageDescriptionBuilder to support fluent coding style.

withHeaderFields

global fferpcore.ProcessMessage.MessageDescriptionBuilder withHeaderFields(Map<String, fferpcore.MessageDescription.Node> fields)

Specifies additional message description fields to include in the process message header. The fields are applied after the standard fields. As a result, standard fields can be overwritten. We recommend prefixing custom header fields with 'X-'.

Input Parameters

Name Type Description
fields Map<String, fferpcore.MessageDescription.Node> Fields keyed by message key.

Return Value

This MessageDescriptionBuilder to support fluent coding style.

withDataFields

global fferpcore.ProcessMessage.MessageDescriptionBuilder withDataFields(Map<String, fferpcore.MessageDescription.Node> fields)

Specifies additional message descripton fields to include in the data part of the process message.

Input Parameters

Name Type Description
fields Map<String, fferpcore.MessageDescription.Node> Fields keyed by message key.

Return Value

This MessageDescriptionBuilder to support fluent coding style.

build

global fferpcore.MessageDescription build()

Constructs a fferpcore.MessageDescription based on the current state of the MessageDescriptionBuilder.

fferpcore.ProcessMessage.ProcessMessageContext

global inherited sharing class ProcessMessageContext extends Context.SObjectContext

fferpcore.Message fferpcore.Context for the Process Message.

This class extends fferpcore.Context.SObjectContext

Methods

ProcessMessageContext

global ProcessMessageContext()

ProcessMessageContext

global ProcessMessageContext(SObjectType subjectType)

The default is for internal use only and is not recommended for use. Use the constructor that takes SObjectType as an argument instead.

getClass

global virtual override Type getClass()

This method is provided to support serialization to Javascript. This method returns the class type of the associated context.

Return Value

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

fferpcore.Context.SObjectContext context = new fferpcore.Context.SObjectContext(ExampleObject__c.SObjectType);

System.assertEquals(fferpcore.Context.SObjectContext.class, context.getClass());

getPotentialChildren

global virtual override List<fferpcore.Context.Source> getPotentialChildren()

This method returns a complete list of the fields on this particular SObject that are in the form of a Context.Source.

Return Value

This service returns a list of Source objects.

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.

/**
 * We will assume the following fields only on ExampleObject__c:
 * Name
 * Email__c
 * Phone__c
 * Address__c
 * In reality use this would return all standard Salesforce fields eg. CreatedById etc
 */

fferpcore.Context.SObjectContext context = new fferpcore.Context.SObjectContext(ExampleObject__c.SObjectType);

List<fferpcore.Context.Source> returnValue = context.getPotentialChildren();

System.assertEquals(4, returnValue.size());

getSource

global virtual override fferpcore.Context.Source getSource(String key)

This method looks up a source by using its key if that key is related to the current context.

Input Parameters

Name Type Description
key String The API name of the field to find.

Return Value

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

/**
 * We will assume the following fields only on ExampleObject__c:
 * Name
 * Email__c
 * Phone__c
 * Address__c
 * In actual use this would return all standard Salesforce fields eg. CreatedById etc
 */

fferpcore.Context.SObjectContext context = new fferpcore.Context.SObjectContext(ExampleObject__c.SObjectType);

fferpcore.Context.Source returnValue = context.getSource('Name');

System.assertEquals('Name', returnValue.getKey());

fferpcore.ProcessMessage.NewProcessMessageDataSource

global with sharing class NewProcessMessageDataSource extends SObjectByIdDataSource

Data source for new processes. This generates process messages with a status of PREPARING and the process token provided.

This class extends fferpcore.SObjectByIdDataSource

Methods

NewProcessMessageDataSource

global NewProcessMessageDataSource(SObjectType objectType, Set<Id> recordIds, String processToken)

Constructs a fferpcore.DataSource for a new process.

Input Parameters

Name Type Description
objectType SObjectType The SObjectType of the records that are the subject of the process.
recordIds Set<Id> The records to send messages for.
processToken String A token to identify this attempt at the process. See the createToken() method.

requireField

global override void requireField(String key)

Implementation of the requireField() method from DataSource.

Input Parameters

Name Type Description
key String The field key. This is either an SObjectField name or one of the CONTEXT_KEY constants from the ProcessMessage class.

runQuery

global override Iterator<fferpcore.DataSource.Row> runQuery()

Implementation of the runQuery() method from DataSource.

fferpcore.ProcessMessage.ExistingProcessMessageDataSource

global with sharing class ExistingProcessMessageDataSource extends SObjectByIdDataSource

Data source for existing processes. This generates process messages with the status, message and upstream data values from the messages parameter.

This class extends fferpcore.SObjectByIdDataSource

Methods

ExistingProcessMessageDataSource

global ExistingProcessMessageDataSource(SObjectType objectType, Map<Id, fferpcore.ProcessMessage> messages)

Constructs an ExistingProcessMessageDataSource.

Input Parameters

Name Type Description
objectType SObjectType The SObjectType of the records that are the subject of the process.
messages Map<Id, fferpcore.ProcessMessage> Map of ProcessMessages keyed by their SubjectId.

requireField

global override void requireField(String key)

Implementation of the requireField() method from DataSource.

Input Parameters

Name Type Description
key String The field key, either an SObjectField name or one of the CONTEXT_KEY constants from the ProcessMessage class.

runQuery

global override Iterator<fferpcore.DataSource.Row> runQuery()

Implementation of the runQuery() method from DataSource.

© Copyright 2009–2023 Certinia Inc. All rights reserved. Various trademarks held by their respective owners.