Last Updated on April 18, 2022 by Rakesh Gupta
Big Idea or Enduring Question:
- How do you resolve the FIELD_CUSTOM_VALIDATION_
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:
- Why errors could occur
- How to identify errors by reading system generated flow error email
- How to solve the problem
After reading this blog, you’ll be able to:
- Understand what is FIELD_CUSTOM_VALIDATION_
- Resolve FIELD_CUSTOM_VALIDATION_
- 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_
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_
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 Denied. Also 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.
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
- Create a validation rule on the Quote object to make the Description field required when Status is Denied.
Proof of Concept
- Create an opportunity record with a few quotes to it, as shown in the following screenshot:
- 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_
The reason for the FIELD_CUSTOM_VALIDATION_
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.
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.
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
- Click Setup.
- In the Quick Find box, type Flows.
- Select Flows then click on the Flow Name that will be modified. In this case, Updated Related Quotes to Denied.
- Click on the Save As button at the top right of the Flow builder.
- 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
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.