All articles

Platform

FIELD_CUSTOM_VALIDATION_EXCEPTION: diagnose the rejected save

Find the rule or addError blocking a Salesforce write and return structured, useful failures to integrations and agent actions.

A rejected save is often the business rule working as intended. Find the rule before changing the integration’s permissions or disabling validation.

FIELD_CUSTOM_VALIDATION_EXCEPTION can come from a validation rule or an Apex addError path. Read the status code, message and associated fields, then reproduce the operation with the same input and executing user. A successful administrator edit doesn’t establish that the integration’s save should succeed.

Preserve the useful error details

Salesforce’s returned database errors guide describes SaveResult and Database.Error. With partial-success DML, inspect every result rather than assuming the whole collection saved.

Database.SaveResult[] results = Database.update(records, false);
for (Integer i = 0; i < results.size(); i++) {
    if (!results[i].isSuccess()) {
        for (Database.Error error : results[i].getErrors()) {
            System.debug(LoggingLevel.WARN, error.getStatusCode());
            // Map the error to records[i] in your controlled result output.
        }
    }
}

This illustrative fragment assumes records is a bounded, authorized update collection. Decide whether partial completion is valid for your operation. If all records must succeed together, a partial-success strategy changes that business contract.

Avoid exposing raw messages containing sensitive values in a public response. Return a stable error category and the correction the authorized caller can make; keep diagnostic details in controlled operational records.

Reproduce the exact transition

Compare old and proposed values. A rule may depend on a status transition, a related field or the user’s assigned custom permission. Test the same change rather than opening the record and saving it without modification.

Inspect active validation rules and relevant trigger handlers. Use the order of execution to understand which automation may modify values before validation. The field that the caller supplied may not be the final value being evaluated.

If an exception to the rule is legitimate, define it narrowly with the rule owner. A broad bypass for every integration or agent write can undermine the process the rule protects.

Give agent actions an honest result

An agent should report that the save was rejected and describe the next permitted step. It should not repeatedly try different values until a protected transition happens to pass.

Test a valid save, a rejected transition and a collection containing both. Assert the result returned to the caller as well as the database state. A useful implementation makes the business restriction understandable without claiming success for a failed write.

Keep reading

All articles