I am having problems with one of our validation rules, which forces me to have an "empty" value in a custom field based on certain conditions.
When editing a field manually through the interface, I simply delete the contents of the text field, and it saves a fine. But with apex code, how can I put an "empty" value inside a field? Assigning a null field does not work. I checked the development console for logs and null is correctly assigned to my property, but the update still throws an exception with a message like:
FIELD_CUSTOM_VALIDATION_EXCEPTION, CustomField; must be blank: [CustomField__c]
This is how I assign null in vertex code:
customObject.CustomField__c = null; update customObject;
Assigning zero does not work either, since the validation rule requires the field to be "empty". Is there a hidden trick that allows me to do this through the top?
EDIT: Here is a validation formula. If it is true, an error occurs:
AND( ISPICKVAL(CustomStatusField ,'Custom Value') , !ISBLANK(CustomField__c )))
So the validation is basically this: when CustomStatusField is equal to 'Custom Value' , CustomField__c should be empty.
EDIT No. 2: I finally solved my problem. The above code worked as expected, but another vile trigger appeared that caused the field to be updated to a value other than zero, which resulted in a denial of the validation rule. God, I hate the widespread use of triggers for business logic!