function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
PyramidPyramid 

Unit test succeeds in sandbox and fails in production

I have a unit test for a trigger which has to create a contact.  LastName is a required field to create a contact.  I use The following statements to create the contact.

 

 

 Contact con= new Contact(accountId=acc.Id,LastName='Test1');
        insert con;       

 

In the sandbox this statement works fine.  But after deploying to the production version when the test is run it fails with the following message:

 

Failure Message: "System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [LastName]: [LastName]", Failure Stack Trace: "Class.TestupdateEvent_HistoryInfo.triggerTest: line 15, column 9 External entry point"

 

Here's hoping someone can guide me out of this forest to a happy resolution

 

Thanks

 

Doug

Pradeep_NavatarPradeep_Navatar

It seems that the fields in sandbox and production system does not match. I think you have forgotten to deploy some of the changes done.

hisrinuhisrinu

Piece of code what ever you have posted is correct, however in the entire test method there might be a problem

 

Follow the best practices from the below url

http://wiki.developerforce.com/index.php/An_Introduction_to_Apex_Code_Test_Methods

 

If you can't solve this then I recommend you to post the test method completely, so that someone can help you

PyramidPyramid

Hisrinu,

 

I checked all the fields in production to make sure that they were identical to those in the sandbox (per Pradeep_Navatar) and now I am publishing the entire unit text code per your own suggestion.

 

 

/*Salesforce.com Extension Doug copied from Shipment
This test class is used to test updateEvent_HistoryInfo trigger
*/
@isTest
private class TestupdateEvent_HistoryInfo {    
    static testMethod void triggerTest(){ 
        
        //insert test account   
        Account acc= new Account(name='Test Account 1.0');
        insert acc;
        //insert test contact        
        Contact con= new Contact(accountId=acc.Id,LastName='Test1',ContactType__c='Other');
        insert con;
        
        //insert test event        
        Event_History__c evt = new Event_History__c(contact__c=con.Id);
        insert evt;
    }
    
}

 

/*Salesforce.com Extension Doug copied from Shipment

This test class is used to test update

Event_HistoryInfo trigger*/

 

@isTest

private class TestupdateEvent_HistoryInfo {    
static testMethod void triggerTest(){               

 

//insert test account         

 Account acc= new Account(name='Test Account 1.0');      

 insert acc;

 //insert test contact                

Contact con= new Contact(accountId=acc.Id,LastName='Test1',ContactType__c='Other');        

insert con;                

 

//insert test event                

Event_History__c evt = new Event_History__c(contact__c=con.Id);      

 insert evt;    

     }  

 

 }

 

I retried it and the same thing happened - in the sandbox the unit test runs OK but after deployment it fails in production with the following message

 

Failure Message: "System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [LastName]: [LastName]", Failure Stack Trace: "Class.TestupdateEvent_HistoryInfo.triggerTest: line 15, column 9 External entry point"

 

Thanks Hisrinu for the suggestion to publish all the code

 

Doug