0

I'm getting this error System.DmlException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, invalid cross reference id: [] Stack Trace ...

This production org is brand new and the change set that we are trying to validate is the first one and has all the fields, class, etc. Also, that deploy from dev sandbox to UAT sandbox was success, it is just failing to UAT sandbox to Production. I get this error in all methods of that test class, here is one method:

public class TestContract {
@isTest static void TestContractPositive(){
    Account acc= TestData.getAccount();
    insert acc;
    Contract record = TestData.generateContractForAccount(acc.Id);                                
    record.StartDate = System.today().addMonths(-12);
    record.TrueEndDate__c = System.today().addMonths(-1);                                                                        
    insert record;
    
    Contract newRecord = TestData.generateContractForAccount(acc.Id);                               
    newRecord.StartDate = System.today(); 
    newRecord.TrueEndDate__c = System.today().addMonths(12);
                                     
    Test.startTest();
    insert newRecord;
    Test.stopTest();
    
    Contract c = [SELECT isTrue__c FROM Contract WHERE Id = :newRecord.Id];
    System.assertEquals(c.isTrue__c, 1);

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.