0

I'm trying to deploy a few items to production. I tested all my classes/triggers and they are all at 90% or higher. Unfortunately, there is a class a consultant had written before I was here that is causing deployment to fail.

Here is the error code. The field is a picklist.

System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Custom Field must be complete.: [Custom_Field_c]

I took a look at the Test Class and noticed that this field was not set when creating the Opportunity object. I went in and added a value for the picklist, so the code woudn't fail. I ran the test and it passed (also works in in Execute Anonymous).

I tried to deploy again and received the error. I disabled the validation rule in the Sandbox, so I'm assuming I may need to disable it in production (but not sure).

Also, I ran a query in the production environment and there were thousands of records with that field blank, so I'm wondering if that could be causing an issue.

Thanks A

1

Short version: you'll need to either deploy that unit test to production first and then redeploy or turn the validation rule off in production. The former should work and is what I'd recommend.

What seems to have happened is:

  1. Unit test written
  2. Many records inserted without custom field
  3. Validation rule added
  4. Old records remain the same, new records must pass validation rule

And it's just a chicken and egg problem with the unit test itself running on sandbox but failing while being sent along with the deploy. Deploy just the unit test, run it on production and if it passes the rest of the deployment should be fine.

| improve this answer | |
  • That's what I was thinking too. I agree with the former as well. Let me see if I can get them to temporarily disable that rule and I'll try to redeploy. – ajl7519 Mar 11 '14 at 19:48
  • I had to turn off the validation rule off in production to get it to deploy. Thanks for the tip. – ajl7519 Mar 18 '14 at 17:47
1

I got the validation rule error even when moving an object .. which is strange. The object does not have any lookup to any other custom/standard object. Then I had to turn the validations off to move the object.

The test classes are re-run while movement to production. The new validation rules added are not covered in the old test classes, which cause these test classes to fail. So an alternative is to either 1) re-write the test classes with the validations included or 2) to turn off these validation rules and move the code to production.

| improve this answer | |

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.