ErpErrorBody
global ErpErrorBody()
Default constuctor for ErpErrorBody. Initially, the fferpcore.ErpErrorBody constructed by this method does not have any errors set on it.
Sample Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
private void checkForErrors(fferpcore.HandleMessagesRequest request)
{
for (fferpcore.DeliveredMessage message : request.getMessages())
{
if (!message.hasResponse())
{
message.respondError( new fferpcore.ErpErrorBody());
}
}
}
|
ErpErrorBody
global ErpErrorBody(String message)
Constructs an fferpcore.ErpErrorBody with the specified error message set on it.
Input Parameters
message |
String |
A string describing the error that has occured. |
Sample Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
private void checkForErrors(fferpcore.HandleMessagesRequest request)
{
for (fferpcore.DeliveredMessage message : request.getMessages())
{
if (!message.hasResponse())
{
message.respondError( new fferpcore.ErpErrorBody( "An error has occured" ));
}
}
}
|
ErpErrorBody
global ErpErrorBody(List<String> messages)
Constructs an fferpcore.ErpErrorBody with the specified list of error messages set on it.
Input Parameters
messages |
List<String> |
A list of strings describing the errors that have occurred. |
Sample Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
private void checkForErrors(fferpcore.HandleMessagesRequest request)
{
for (fferpcore.DeliveredMessage message : request.getMessages())
{
List<String> errors = handleMessage(message);
if (errors.size() > 0 )
{
message.respondError( new fferpcore.ErpErrorBody(errors));
}
}
}
|
addErrorMessage
global void addErrorMessage(String message)
Used to add an error message to the body of a failed message delivery.
Input Parameters
message |
String |
The text that will be displayed in the message. |
Sample Code
1 2 3 4 5 6 7 8 9 10 11 12 13 | public fferpcore.ErpErrorBody buildErrorBody(List<Database.Error> errors)
{
fferpcore.ErpErrorBody body = new ErpErrorBody();
for (Database.Error error : errors)
{
body.addErrorMessage(error.getMessage());
}
return body;
}
|
getErpErrorBodyVersion
global Integer getErpErrorBodyVersion()
Returns the version number of ErpErrorBody.
Return Value
This service returns an Integer object.
Sample Code
1 2 3 4 5 6 7 | Integer expectedVersion = 5 ;
fferpcore.ErpErrorBody errorBody = getErrorBody();
System.assertEquals(expectedVersion, errorBody.getErpErrorBodyVersion());
|
getErrorMessages
global List<String> getErrorMessages()
Returns the list of error messages assocaiated with this ErpErrorBody.
Return Value
This service returns a list of Errors as string objects.
Sample Code
1 2 3 4 5 6 7 | fferpcore.ErpErrorBody errorBody = new fferpcore.ErpErrorBody( 'Test message' );
System.assertEquals( 1 , errorBody.getErrorMessages().size());
System.assertEquals( 'Test message' , errorBody.getErrorMessages().get( 0 ), 'The error provided should be the first error in the list.' );
|
serialize
global virtual String serialize()
Returns a serialized version of the ErpErrorBody. The default implementation returns the object serialized into JSON format. If the the method is overridden on a subclass, the behavior may be different.
Return Value
This service returns a JSON representation of this error body.
Sample Code
1 2 3 4 5 6 7 | fferpcore.ErpErrorBody errorBody = getErrorBody();
String serializedErrorBody = errorBody.serialized();
|
deserialize
global static fferpcore.ErpErrorBody deserialize(String jsonString)
A static method that constructs an fferpcore.ErpErrorBody from a JSON string parameter. It reverses the effect of the serialize method.
Return Value
This method returns an ErpErrorBody.ErpErrorBody object. If the provided parameter is not a valid JSON string or does not contain either a ErrorMessages or ErpErrorBodyVersion field then null is returned. Extra fields are ignored.
Sample Code
1 2 3 4 5 6 7 8 9 10 | fferpcore.ErpErrorBody originalErrorBody = new fferpcore.ErpErrorBody( 'Error' );
String jsonString = oroginalErrorBody.serialize();
fferpcore.ErpErrorBody newErrorBody = fferpcore.ErpErrorBody.deserialize(jsonString);
System.assertEquals(oroginalErrorBody, newErrorBody, 'Recreated object should equal original object' );
|
getDescription
global static fferpcore.MessageDescription.Node getDescription()
This static method returns an fferpcore.MessageDescription.Node describing the structure of an ErpErrorBody.
Return Value
This service returns an MessageDescription.Node object.
Sample Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | /**
* Generates a description node describing a message.
*/
global static fferpcore.MessageDescription.Node getDescriptionNode(Schema.SObjectType context)
{
Schema.SObjectField idField = context.getDescribe().fields.getMap().get( 'Id' );
fferpcore.MessageDescription.MapNode root = new fferpcore.MessageDescription.MapNode()
.withChild( 'ObjectId' , new fferpcore.MessageDescription.ScalarNode( new fferpcore.Context.SObjectSource(idField)))
.withChild( 'ErrorBody' , fferpcore.ErpErrorBody.getDescription());
return root;
}
|
equals
global Boolean equals(Object obj)
Indicates when one fferpcore.ErpErrorBody is equal to another. Two ErpErrorBodys are considered equals if they have the same version and list of error messages.
Input Parameters
obj |
Object |
The object we are checking equality against. |
Sample Code
1 2 3 4 5 6 7 8 9 10 | fferpcore.ErpErrorBody errorBody1 = new fferpcore.ErpErrorBody( 'Error' );
fferpcore.ErpErrorBody errorBody2 = new fferpcore.ErpErrorBody( 'More Errors' );
fferpcore.ErpErrorBody errorBody3 = new fferpcore.ErpErrorBody(List<String>{ 'Error' });
System. assert (!errorBody1.equals(errorBody2), 'These are not equal as the error messages are different' );
System. assert (errorBody1.equals(errorBody3), 'These are equal as they have the same version and error messages' );
|
hashcode
global Integer hashcode()
Returns an Integer computed from the Version and Error Messages of this object.
Sample Code
1 2 3 4 5 6 7 8 9 | fferpcore.ErpErrorBody errorBody1 = new fferpcore.ErpErrorBody( 'Error' );
fferpcore.ErpErrorBody errorBody2 = new fferpcore.ErpErrorBody(List<String>{ 'Error' });
System.assertEquals(errorBody1.equals(errorBody2), 'These are equal as they have the same version and error messages' );
System.assertEquals(errorBody1.hashcode(), errorBody2.hashcode());
|