While setting up a test fixture, my code fails when a FIELD_CUSTOM_VALIDATION_EXCEPTION is thrown during an Account record update. Here is the relevant part:
theAccount = [select Id, Status__c, Attitude__c, Phone_Number_Confirmed__c from Account where Id = :theAccount.Id limit 1];
system.debug('#### Status: ' + theAccount.Status__c); // Visitor
system.debug('#### Attitude: ' + theAccount.Attitude__c); // Positive
system.debug('#### Confirmed: ' + theAccount.Phone_Number_Confirmed__c); // true
theAccount.Status__c = 'Local Contact Requested';
update theAccount; // Throws FIELD_CUSTOM_VALIDATION_EXCEPTION
The exception error message refers to an Account validation rule that has this Error Condition Formula:
ISPICKVAL(Status__c ,"Local Contact Requested" ) &&
( NOT(Phone_Number_Confirmed__pc) ||
ISPICKVAL(Attitude__c,"Unknown") ||
ISPICKVAL(Attitude__c,"Hostile") ||
ISPICKVAL(Attitude__c,"Unclear") )
It looks like my account record satisfies all the validation criteria, so I am not sure why it is tripping over this validation rule. Can something else (like user role / permissions, field access, other validation rules etc) cause this exception?