I'm having problems with one of our custom validation rules that forces me to have 'blank' value in a custom field based on certain conditions.
When editing the field manually through the interface, I just erase the content of the text box and it saves fine. But with apex code, how can I put the 'blank' value inside the field? Assigning null to the field does not seem to make it work. I checked the developer console for the logs and null is correctly being 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]
Here is how I assign null in the apex code :
customObject.CustomField__c = null;
Assigning zero does not work either, as the validation rule needs the field to be 'blank'. Is there a hidden trick which allows me to do this through apex?
Here is the validation formula. If it evaluates to true, there is an error :
AND( ISPICKVAL(CustomStatusField ,'Custom Value') , !ISBLANK(CustomField__c )))
So the validation basically is: When
CustomStatusField is equal to
CustomField__c must be blank.