[SalesForce] ISNEW() Validation rule causing triggers to fail

I created the following validation rule on my contact records:

IF( ISNEW()&& ( FormAssembly__c =""&& 
TEXT(LeadSource)="") 
&& 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

Best Answer

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.

Related Topic