Validation Warning Source Code and Examples
The OperationValidator class provides three methods to report validation errors at the record and field levels. When you call any of these methods in the validation code, errors are automatically added to the response that appears in the UI. Validators can report errors and warnings.
//Adds a validation error that affects the full record
protected void addRecordValidationError(String errorMessage)

//Adds a field validation error
protected void addFieldValidationError(String fieldFullIdentifier, String errorMessage)

//Adds a relationship validation error
protected void addRelationshipValidationError(String relationshipFullIdentifier, String errorMessage)
You can configure validation logic to add errors when issues are found by extending com.servicemax.core.validator.OperationValidator with the addFieldValidationError(), addRelationshipValidationError(), and addRecordValidationError() methods. Warnings rely on the same logic, but unlike errors, can be ignored.
To configure validation warnings to make transactions fail, invoke the following method from the current transaction.
public void failOnValidationWarnings();
You can use the following methods for the OperationValidation class to add warnings to validator logic.
/**
* Adds a validation warning that affects all the record.
*
* @param warningMessage the warning message
*/
protected void addRecordValidationWarning(String warningMessage);

/**
* Adds a field validation warning.
*
* @param fieldFullIdentifier the field full identifier
* @param warningMessage the warning message
*/
protected void addFieldValidationWarning(String fieldFullIdentifier, String warningMessage, Object... params )


/**
* Adds a relationship validation warning
*
* @param relationshipFullIdentifier the relationship full identifier
* @param warningMessage the warning message
*/
protected void addRelationshipValidationWarning(String relationshipFullIdentifier, String warningMessage, Object... params)
Validation Warning Code Examples
The following validation code in operations and event handlers causes validation warnings to trigger transactions to fail.
Max.executeAsAdmin( { ->
def newRecord = Record.newRecord("io_basic_object_for_test")
newRecord.io_owner = UUID.randomUUID()
newRecord.io_name = "b name"
Max.currentTransaction().failOnValidationWarnings()

Database.upsert(newRecord)

})
Alternatively, you can configure this functionality if your logic calls a REST API by calling the REST operation and adding the following parameter.
&iop_fail_on_validation_warnings parameter=true|false
When set to true, vaidation warnings triggered while calling the REST API service cause transactions to fail. When set to false or not specified, validation warnings are ignored.
* 
For details on configuring custom data validation, see Working With Data Validation Options in Service Board for Implementers.
For more information:
Was this helpful?