+ Start a Discussion
Lukasz PiziakLukasz Piziak 

Deploy failed - Apex class tests (ChatterAnswersCreateAccountTest)

Hi,

I have a problem with deploying my first app after checking and testing from sandbox to production. All components passed test but  problem is with Apex Tests. Please see details below:

Code Coverage Failure (your organization's code coverage is 6%. You need at least 75% coverage to complete this deployment.
  • Class Name: "ChatterAnswersCreateAccountTest"
  • Method Name: "validateAccountCreation"
  • Error description: " 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"

My sanbox wasn't synced with production before.
I have found that in production this missing field [MFG_Account_Number__c]: is set as a required field and in sandbox as required and unique. I have changed settings to have the same on both environments (required only) and tryied again to deploy. Unfortunately I'm getting the same error message. 

It is strange because this kind of component is not related to my custom app and I cant figure out what is a connection between my aplication and this Apex Class in production.

Addiotionaly I have reruned the test for this Apex Class and it says failed as a result.
Can someone help me with fixing this apex in production (I suspect that this has to be done first) and then what kind of modification I have to do to successfully deploy my App in to production. 

It is frustrating that native code from salesforce cannot be as a subject of getting help from salesforce help & training platform.
Every help is greatly apprecitated. 


bob_buzzardbob_buzzard
What happens if you run the unit tests directly in production rather than as part of your deployment? It sounds like there is some other test code in production that is failing because of a missing required field.  Unfortunately you'll need to fix that test in order to be able to deploy your changes to production, as Salesforce requires 75% test coverage and doesn't care whose fault the failures are.
Lukasz PiziakLukasz Piziak
Hi,
Please see below results of unit test only:

Class ChatterAnswersCreateAccountTest
Method Name validateAccountCreation Pass/Fail Fail
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

The unit test I have done by basically finding this Apex Class and clicking run test button - Is this a correct or is there another place to do unit test?
Lukasz PiziakLukasz Piziak
Hi Bob,

Can you help me to fix this test?
bob_buzzardbob_buzzard
The problem with the test is that it isn't supplied a field that is now mandatory when it creates an account.  It should be a simple matter of adding that field to the test record.
Lukasz PiziakLukasz Piziak
Can you please tell me of how to do it? I'm very new to salesforce and have no clue of how to amend this field to the test record.
Thank  you.
bob_buzzardbob_buzzard
You'll need to find the developer that wrote the test and get them to fix it I'm afraid.