How to Fix FIELD_CUSTOM_VALIDATION_EXCEPTION Error

How to Fix FIELD_CUSTOM_VALIDATION_EXCEPTION Error

Last Updated on April 18, 2022 by Rakesh Gupta

Big Idea or Enduring Question:

  • How do you resolve the FIELD_CUSTOM_VALIDATION_EXCEPTION error? 

The Record-Triggered Flow is a way of automating business processes. Record-Triggered Flow is a powerful tool for system administrators and developers to implement business processes without writing code. However, with great power comes great responsibility –  If a user starts creating a new flow for each requirement – or creating flows without understanding Salesforce limitations – then, a user may encounter many issues, either in the future or, while the testing/deployment phase.

In my last post How to Fix MIXED DML Operation Error, I discussed how to solve Mixed Data Manipulation Language (DML) Operation Error by using a Scheduled path. The Scheduled path separates DML operations, on Setup and non-Setup Objects, in the same process, and, thereby, avoids incurring a Mixed DML operation error.

This article goes one step further; it discusses another common error   FIELD_CUSTOM_VALIDATION_EXCEPTION Error. The article will help you to understand the following items:  

  1. Why errors could occur
  2. How to identify errors by reading system generated flow error email
  3. How to solve the problem

Objectives:

After reading this blog, you’ll be able to: 

  • Understand what is FIELD_CUSTOM_VALIDATION_EXCEPTION error
  • Resolve FIELD_CUSTOM_VALIDATION_EXCEPTION error
  • and much more

Business Use case

Tamara McCleary is working as a System Administrator at Gurukul on Cloud (GoC). They use Salesforce to manage Opportunities and Quotes, and each Opportunity can have multiple Quotes. Whenever a customer accepts a Quote, all other Quote records related to that opportunity should have the Status updated to Denied. 

What is FIELD_CUSTOM_VALIDATION_EXCEPTION Error?  

Let’s say that you have created a record-triggered flow on the Lead object to perform some DML operation. Now you are updating 1K records via Data Loader, which triggers the record-triggered flow on the Lead object. If the record-triggered flow fails on any record due to a Validation Rule/Required Fields/Apex Trigger (intervening in between if you have any), it currently causes the entire batch to roll back and you will encounter FIELD_CUSTOM_VALIDATION_EXCEPTION Error.

Below, I will show you how, if there is a validation rule defined on an object, and the validation error conditions are met, a flow fails and throws a rolled_back error to a user. 

Before we start, assume that there is a Validation rule defined on the Quote Object. It states that the Description field must be populated – or cannot be null – if the Status field, on the Quote Object, updates to DeniedAlso assume that the Description field, on one of the Quotes, was left blank.

In light of the above, first, let us update Opportunity Stage to Closed Lost. This will trigger our Process on the Opportunity Object and auto-update related Quotes Status to Denied.

This, in turn, will generate an ALL_OR_NONE_OPERATION_ROLLED_BACK error because, as mentioned earlier, there is a validation rule defined on the Quote Object to make sure that, if someone updates the Status to Denied then, Quote Description field cannot be null.

Next, we will use Error Email, to identify the root cause of flow failure.

And then, finally, we will update our flow – based on the root cause failure captured from the debug log – by populating the Description field and, thereby, solving the ALL_OR_NONE_OPERATION_ROLLED_BACK error.

Pre-requisites

Please go through this article first and make sure to complete the listed steps Update Related Quotes to Denied Except for the One That Was Accepted

Write a Validation Rule that Generates a FIELD_CUSTOM_VALIDATION_EXCEPTION Error

  1. Create a validation rule on the Quote object to make the Description field required when Status is Denied

Validation Rule - Required Description field

Proof of Concept

  1. Create an opportunity record with a few quotes to it, as shown in the following screenshot:
  2. Make sure that one of the quotes does not have a Description field populated. The next step is to update Quote Stage to Accepted, Boooommmm, you encounter a FIELD_CUSTOM_VALIDATION_EXCEPTION error, as shown in the following screenshot:

👉  Flow fault error email which is sent to the creator of the Process that is failing, is unable to explain the reason behind the FIELD_CUSTOM_VALIDATION_EXCEPTION error. Currently, as per the flow design, if a record fails at runtime, then the entire batch will rollback. 

The reason for the FIELD_CUSTOM_VALIDATION_EXCEPTION error is that currently Salesforce flow is designed to work only when header allOrNone is true. In another word, Salesforce Flow will roll back all changes unless all records are processed successfully.

To solve the same error in Apex, you use the Database class method. By using the method, you can specify whether or not to allow for partial record processing if errors are encountered. You can do so by passing an additional second Boolean parameter. If you specify false for this parameter and if a record fails, the remainder of DML operations can still succeed.

Database.update(opptList, false);

By default, this allOrNone parameter is true, which means that if at least one sObject cannot be processed, all remaining sObjects will fail to process and, an exception will be thrown for the record that causes a failure.

Fix FIELD_CUSTOM_VALIDATION_EXCEPTION Error

To fix the ALL_OR_NONE_OPERATION_ROLLED_BACK error in a Flow, we have to update the Flow and add the Description field to it. Perform the following instructions to solve the ALL_OR_NONE_OPERATION_ROLLED_BACK error in a Flow: 

Step 1: Clone Existing Flow 

  1. Click Setup.
  2. In the Quick Find box, type Flows.
  3. Select Flows then click on the Flow Name that will be modified. In this case, Updated Related Quotes to Denied.
  4. Click on the Save As button at the top right of the Flow builder.
  5. Click Save.

Step 2: Modify Update Records Element to add Description 

The next step is to modify the Update Related Quotes action to add the Description field to it, as shown in the following screenshot:

In the end, Tamara’s Flow will look like the following screenshot:

Almost there! Once everything looks good, click the Activate button.  

Proof of Concept

  1. Now update the Quote Status to Accepted. Notice that, Related Quotes are updated by the Flow.

Formative Assessment:

I want to hear from you!

What is one thing you learned from this post? How do you envision applying this new knowledge in the real world? Feel free to share in the comments below.

Have feedback, suggestions for posts, or need more information about Salesforce online training offered by me? Say hello, and leave a message!

Preferred Timing(required)

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Automation Champion

Subscribe now to keep reading and get access to the full archive.

Continue reading