I created the following validation rule on my contact records:

IF( ISNEW()&& ( FormAssembly__c =""&& 
&& TEXT(Contact_Source_List__c) ="",TRUE,FALSE)

I went to validate a new custom object and fields that has a master-detail relationship to contacts. I got an error that two Apex tests had failed and that I don't have enough test code coverage (never had this issue before). Both errors referred to the validation rule. I tried deactivating the validation rule and then validating the inbound change set again to test, and it succeeded with no problem. Hence, I'm pretty sure the validation rule was the cause of the original failure.

I'm still a newbie with code, so I don't really know how to go about troubleshooting this! Any help would be much appreciated!enter image description here

Saw a few other posts on similar issues: Validation Rule Causing Deployment Issue How to bypass Validation logic in a Trigger

  • To prevent hitting this only when deploying, make sure to run all apex tests after doing changes in a sandbox environment. Configuration changes can break or change apex behavoir, and their impact should be tested and verified. Aug 21, 2014 at 16:09

2 Answers 2


What's happening is that your new validation rule is causing two of your test classes to fail. Those test classes need to be updated such that they can pass the validation rule when the test class runs on the triggers. That's why your code coverage dropped. Test classes typically need to create test data. Your validation rule is preventing the test class from creating the data most likely because the programmer who wrote the test class never anticipated the need to pass a rule such as you've written.

Bottom line, the two classes (TestRelationshipRollup.MyUnitTest() method and MyProfilePageControllerTest.TestSave() method )will need to be updated such that they can pass the validation rule if you wish to implement it.


By the looks of it the testSave method in MyProfilePageControllerTest and the myUnitTest method in TestRelationshipRollup are trying to call insert on records that do not meet the criteria of your validation rule.

You should go into those classes and make sure that the FormAssembly__c, LeadSource and Contact_Source_List__c fields are populated on any Contact objects those test classes try to insert into the database.

  • Thanks. This makes sense. Since this test code is part of the NPSP, I can't edit it myself to add in the field values. Is there any way I can modify my validation rule criteria so that the test will pass without those field values?
    – JodiNA
    Aug 21, 2014 at 16:23
  • You'll either have disable the VR or bypass it (see salesforce.stackexchange.com/questions/63/…). Maybe your test class could set a custom setting value to effectively disable the rule?
    – Mike Chale
    Aug 21, 2014 at 16:42
  • Instead of rewriting the test code, I added to the validation formula. Now it includes the contact information used in the test insert so when the test code runs the validation rule isn't triggered. Worked like a charm! Thanks for your help!!
    – JodiNA
    Aug 21, 2014 at 16:45
  • Thanks for the stack exchange link. Looks like my solution was one of the ones someone there mentioned, but I will keep this as reference.
    – JodiNA
    Aug 21, 2014 at 16:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .