Foundations Apex API Developer Reference

fferpcore.ErpErrorBody

global inherited sharing virtual class ErpErrorBody

Methods

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

//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());
        }
    }
}

ErpErrorBody

global ErpErrorBody(String message)

Constructs an fferpcore.ErpErrorBody with the specified error message set on it.

Input Parameters

Name Type Description
message String A string describing the error that has occured.

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 occured"));
        }
    }
}

ErpErrorBody

global ErpErrorBody(List<String> messages)

Constructs an fferpcore.ErpErrorBody with the specified list of error messages set on it.

Input Parameters

Name Type Description
messages List<String> A list of strings describing the errors that have occurred.

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())
    {
        //handleMessage has been implemented to return a list of error messages.
        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

Name Type Description
message String The text that will be displayed in the 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.

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

//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.

Integer expectedVersion = 5;
fferpcore.ErpErrorBody errorBody = getErrorBody(); // get an ErpErrorBody from somewhere
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

//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.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

//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.ErpErrorBody errorBody = getErrorBody(); // get an ErpErrorBody from somewhere
String serializedErrorBody = errorBody.serialized();
//The serialized error body may be persisted at this point.

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

//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.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

//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.

/**
 * 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

Name Type Description
obj Object The object we are checking equality against.

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.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

//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.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());
© Copyright 2009–2022 FinancialForce.com, inc. Confidential – all rights reserved. Various trademarks held by their respective owners.