function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Eliezer Augusto Javier Bautista 7Eliezer Augusto Javier Bautista 7 

FIELD_CUSTOM_VALIDATION_EXCEPTION Insert

I get this error in every test class :

System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Required Field: []

The error comes at every  "Insert " function 



 
Best Answer chosen by Eliezer Augusto Javier Bautista 7
Julien SalensonJulien Salenson
Hi Eliezer,

To complete the Harsh answer :
FIELD_CUSTOM_VALIDATION_EXCEPTION, Required Field: []" is indicating that there's a field itself is mark a requiredcustom validation rule or trigger (it's rarer) in your Salesforce organization that enforces a required field, and you haven't provided a value for that field when performing an insert operation.

To resolve this issue, you should do the following:
  • Identify the Required Field: You need to determine which field is causing the issue. The error message currently shows an empty field name "Required Field: []". You should find out which field is required by the field itself, a validation rule or trigger.
    • =>Check for Validation Rules in the object.
 
  • Provide a Value for the Required Field: Once you know which field is required, make sure you provide a value for that field when inserting the record in your Apex test class. For example:
YourObject__c record = new YourObject__c();
record.RequiredField__c = 'Some Value'; // Provide a value for the required field
insert record;
  • Update Test Data: It's important to ensure that your test data meets the validation criteria defined in your organization.

Please mark this comment as best answer if it's help you.

All Answers

HarshHarsh (Salesforce Developers) 
Hi Eliezer,

Did you check that all the required fields are added in the code while inserting?

Thanks
Julien SalensonJulien Salenson
Hi Eliezer,

To complete the Harsh answer :
FIELD_CUSTOM_VALIDATION_EXCEPTION, Required Field: []" is indicating that there's a field itself is mark a requiredcustom validation rule or trigger (it's rarer) in your Salesforce organization that enforces a required field, and you haven't provided a value for that field when performing an insert operation.

To resolve this issue, you should do the following:
  • Identify the Required Field: You need to determine which field is causing the issue. The error message currently shows an empty field name "Required Field: []". You should find out which field is required by the field itself, a validation rule or trigger.
    • =>Check for Validation Rules in the object.
 
  • Provide a Value for the Required Field: Once you know which field is required, make sure you provide a value for that field when inserting the record in your Apex test class. For example:
YourObject__c record = new YourObject__c();
record.RequiredField__c = 'Some Value'; // Provide a value for the required field
insert record;
  • Update Test Data: It's important to ensure that your test data meets the validation criteria defined in your organization.

Please mark this comment as best answer if it's help you.
This was selected as the best answer