How does field_custom_validation_exception happen without upserting the field?

593    Asked by alexDuncan in Salesforce , Asked on Sep 23, 2022

 I wrote a script to export the data to SFDC using the bulk API 2.0 I upserts a bunch of user ids which is an external id of the object. I was expecting it to return errors "REQUIRED_FIELD_MISSING:Required fields are missing" if the entry already exists, or upserting success if it doesn't. However I received this error:


`FIELD_CUSTOM_VALIDATION_EXCEPTION:{Field f} can only be selected by an {Field f SDR}:Field_f__c`

My question is, I didn't include Field_f__c in my csv file, so I did not intend to update it. Why did I trigger a validation exception in this field?


Answered by Amanda Hawes

FIELD_CUSTOM_VALIDATION_EXCEPTION means that there is a validation rule defined in your org and the record you are updating does not meet this rule. When you update a record the entire record is checked against validation rules, even if you are not modifying those fields (unless you have something like ISCHANGED() in your validation rule).


You're getting the error because you are attempting to update a record that is in violation of a rule, most likely because the record was created before the rule existed.

Otherwise, the rule is simply coded incorrectly. If you can find the validation rule that is throwing the error and provide it, we might be able to help you adjust the rule so that it doesn't continue to fail.

Lastly, my company uses a generic admin user that is exempted from all validation rules when doing bulk imports to avoid errors like this. The validation could be updated to have an exclusion for your API user. Something like NOT($User.Alias = 'BULKUSER')



Your Answer

Interviews

Parent Categories