4

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?

7

Your validation rule is using the Person Account field Phone_Number_Confirmed__pc and your Apex code is using the custom field on Account Phone_Number_Confirmed__c. The __pc indicates that its a Person Account field.

Try updating the debugging in your code to print out Phone_Number_Confirmed__pc and you may find that it is actually false.

  • 3
    That's it! Brilliant. Man I love this community. – JannieT Jun 19 '15 at 10:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.