+ Start a Discussion
Lukasz PiziakLukasz Piziak 

Deployment failed due to problem with Apex Tests.

Hi,

During deploying my App from sandbox to production environment I have got 1 error message that Apex Test is Failed. I have included the missing field mentioned in Error Message and after another deploying again i'm getting the same failure. 

Please see screenshot:

What to do to fix my issue?
Thanks for any help
Apex Test Error message

James LoghryJames Loghry
It's hard to read your unit test failure, but I think I got the gist of it.

The issue is with your unit test, not the actual deployment of any custom objects or fields.

In your ChatterAnswersCreateAccountTestvalidateAccountCreation method, you'll need to set a value on "MFG_Account_Number__c" in which ever object you're creating at line 11.  

My guess is at some point, your production and sandbox environments became out of sync.  Someone set the MFG_Account_Number__c field as required in production, but forgot to set it required in sandbox.
Lukasz PiziakLukasz Piziak
Hi James,

Thank you for a quick reply.

This is what the Error message is containing:

"System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [MFG_Account_Number__c]: [MFG_Account_Number__c]
Stack Trace: Class.ChatterAnswersRegistration.createAccount: line 8, column 1 Class.ChatterAnswersCreateAccountTest.validateAccountCreation: line 11, column 1"

If I change the [MFG_Account_Number__c] field as required in sandbox and then add this again to my change sets it should fixed the problem?
James LoghryJames Loghry
If you change the field to required in sandbox, your test should fail the same way in sandbox, but it will be consistent with your results in production.

However, this will allow you to fix and to test your fix for the error you are seeging in your ChatterAnswersCreateAccountTest.validateAccountCreation method in sandbox.

I would suggest the following:
  • Mark the field as required in sandbox.
  • Rerun your test without any modifcations to the test class / method itself. 
  • Veriy that you see the same exception thrown.
  • Fix your test class (in sandbox) by setting the MFG_Account_Number__c field when you create your records in your test method.
  • Verify that your test class is working properly in sandbox.
  • Redeploy to production.
Lukasz PiziakLukasz Piziak
James,

Thank you for al your help.
I'm new to Salesforce and some your suggestions are not clear for me.
  • Could you please advise where I should rerun test without any modifications to the test class/method itself?
  • Where in sandbox I should fix test class by setting the MFG_Account_Number__c field ?
  • How to verify if my test class is working properly in sandbox?
My apologies if this is annoying you, but it is my first deploy to production.

Lukasz PiziakLukasz Piziak
James,

What I gathered this Apex Class exists in production but is not exist in sandbox.
I reruned the test and result is failed:
  • Error Message - System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [MFG_Account_Number__c]: [MFG_Account_Number__c]
  • Stack Trace Class.ChatterAnswersRegistration.createAccount: line 8, column 1
    Class.ChatterAnswersCreateAccountTest.validateAccountCreation: line 11, column 1
wendy kistonwendy kiston
Finally i have change my website PerYourHealth (https://www-peryourhealth.net/) an apps after reading the entire soluation here. 
Suraj Tripathi 47Suraj Tripathi 47
Hi Lukasz, 

You miss a required field MFG_Account_Number__c in class ChatterAnswerRegistration method createAccount Line 8 AND Class chatterAnswerCreateAccountTest method validateAccountCreation line 11.
Or Please check custom field in prod present or not.
Or You can take help by set debug log in Prod. 


I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Suraj