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
Benjamin LeeBenjamin Lee 

My changeset showed error from components that were not deployed

I have created a trigger which will change the asset date field when contract date changes.
The test codes only worked with Account, Contacts and Assets.
At the Sandbox, everything works fine with a 96% coverage, but it fails badly in production

It says at deployment validation that:
Component Errors

 

API Name
Type
Line
Column
Error Message
0 0 TestCaseEscalationAndOthers.CaseEscalationTest(), Details: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Please enter the Phone Number (Format : Std Code-Phone Number): [Phone] Class.TestCaseEscalationAndOthers.CaseEscalationTest: line 8, column 1
0 0 CaseUpdateJobScheduler.CaseUpdateJobScheduler1(), Details: System.AsyncException: The Apex job named "Case Subject Update" is already scheduled for execution. Class.CaseUpdateJobScheduler.start: line 7, column 1
0 0 ApexScheduledClass.testSchedule(); null, Details: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Please enter the Phone Number (Format : Std Code-Phone Number): [Phone] Class.ApexScheduledClass.testSchedule: line 59, column 1; Average test coverage across all Apex Classes and Triggers is 27%, at least 75% test coverage is required.
0 0 updateCasesAfter60Mins.updateCasesAfter60Mins(), Details: System.DmlException: Update failed. First exception on row 122 with id 500w000000nwwg5AAA; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Contact does not belong to the specified Account: [ContactId] Class.updateCasesAfter60Mins.UpdateOpenCases: line 18, column 1 Class.updateCasesAfter60Mins.updateCasesAfter60Mins: line 25, column 1

Apex Test Failures

 

Class Name
Method Name
Error Message
ApexScheduledClass testSchedule System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Please enter the Phone Number (Format : Std Code-Phone Number): [Phone] 
Stack Trace: Class.ApexScheduledClass.testSchedule: line 59, column 1
CaseUpdateJobScheduler CaseUpdateJobScheduler1 System.AsyncException: The Apex job named "Case Subject Update" is already scheduled for execution. 
Stack Trace: Class.CaseUpdateJobScheduler.start: line 7, column 1
TestCaseEscalationAndOthers CaseEscalationTest System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Please enter the Phone Number (Format : Std Code-Phone Number): [Phone] 
Stack Trace: Class.TestCaseEscalationAndOthers.CaseEscalationTest: line 8, column 1
updateCasesAfter60Mins updateCasesAfter60Mins System.DmlException: Update failed. First exception on row 122 with id 500w000000nwwg5AAA; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Contact does not belong to the specified Account: [ContactId] 
Stack Trace: Class.updateCasesAfter60Mins.UpdateOpenCases: line 18, column 1 Class.updateCasesAfter60Mins.updateCasesAfter60Mins: line 25, column 1

Those components that failed were not what Iadded to my change sets for deployment.
Why do they show error here?

Any help is appreciated.

Ben
Best Answer chosen by Benjamin Lee
Keyur  ModiKeyur Modi
Hi,
whenver we used to deploy or validate the changeset it will run all the test class.
For Example if i created one workflow and one custom field in the sandbox and if i triy to move it to deployment at that time it will run all the test classes, so validation or deployment test class execution will be for all it will not related to component,

second question is the issue with validation error.

"0 0 TestCaseEscalationAndOthers.CaseEscalationTest(), Details: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Please enter the Phone Number (Format : Std Code-Phone Number): [Phone] Class.TestCaseEscalationAndOthers.CaseEscalationTest: line 8, column 1'

if we see the this error where highlighted part is main issue. so in that it clearly defined that one custom validation is there , having error "please enter phone Number(format :std Code-Phone Number).
please check the list of validations in your production instance. you can serach validaiton based on error message.

now if we see the second error

"FIELD_CUSTOM_VALIDATION_EXCEPTION, Contact does not belong to the specified Account: [ContactId] Class.updateCasesAfter60Mins.UpdateOpenCases: line 18, column 1 "

so this error again comming from the custom validation so please check it once the list of validations.

So, if you deactivate thoes two validaiton from prodution instace and try to validate it . you will not get any error.


Please let me know if this will help you,

Thanks,
Keyur Modi
 

All Answers

Keyur  ModiKeyur Modi
Hi,
This all error is comming becuse in your production instance there is new validation implemented on the case object where phone number is mendatory, so due to that this is happening,
to resolve this issue you can either deactivate that validation and try to deploy your change set .. or else you put phone number in your all test classes whereever you are getting the error.

Please let me know if this will help,

Thanks,
Keyur Modi
Keyur  ModiKeyur Modi
Hi,
I forgot to inform you that there must be two validation implemented on the production instance where one have that validation error like "Please enter the Phone Number (Format : Std Code-Phone Number)" and another have validation like "Contact does not belong to the specified Account:" . So please check list of validations with respective objects,

please let me know, if this will help.

Thanks,
Keyur Modi
Benjamin LeeBenjamin Lee
Hi Keyur,

Thanks for the help. I still can't get it to work.
However my trigger or test codes did not invoke a creation of case.
Yet it seems the following classes were giving errors:

1. ApexScheduledClass 
2. TestCaseEscalationAndOthers (I am not even calling for this test class to be tested why is it giving error?)
3. CaseUpdateJobScheduler
4. updateCasesAfter60Mins

My change set only has the follwoing two components, but other non related classes also got tested.
I am concerned that my change set also included other test classes but the below only showed those two which I chose.
User-added image

Below are the codes for the two components

-------------------------------------------------------------------------------------------------------------
My Trigger ConUpdateInstConDate is:
trigger ConUpdateInstConDate on Contract (before update) {
    
    List<ID> conIDs = new List<ID>();
    List<String> conStat = new List<String>();
    List<date> conDate = new List<date>();
    
    for(Contract con : Trigger.new){
        
        Contract oldCon = Trigger.oldMap.get(con.Id);
        
        Boolean draftToActive = oldCon.Status.equals('Draft') && con.Status.equals('Activated');
        Boolean oldConNoChange = oldCon.StartDate == con.StartDate;
        Boolean oldTermNoChange = oldCon.ContractTerm == con.ContractTerm;
        Boolean conActivated = con.Status.equals('Activated');
        
        date dt = con.StartDate.addMonths(con.ContractTerm);
        
        if((!oldConNoChange && conActivated) || (!oldTermNoChange && conActivated) || draftToActive){
            
            conIDs.add(con.Installed_Asset__c);
            conStat.add(con.Contract_Type__c);
            conDate.add(dt);
            System.debug('ID is: '+ con.Id + 'Old date is: ' + dt);
        }
    }
    
    ID [] conIDArray = conIDs;
    String [] statArray = conStat;
    date [] conDateArray = conDate;
    
    System.debug('conIDs size is: ' + conIDArray.size());
    System.debug('conIDs size is: ' + conDateArray.size());
    
    List<Installed_Asset__c> inst = [SELECT id, AMC_End_Date__c, CMC_End_Date__c FROM Installed_Asset__c WHERE id in :conIDs];
    
    boolean instNotEmpty = false;
    
    if(!inst.isEmpty()){
        instNotEmpty = true;
    }
    
    for(integer i=0; i < inst.size(); i++){
        
        if(conStat[i] == 'AMC'){
           inst[i].AMC_End_Date__c = conDate[i]; 
        }
        else{
            inst[i].CMC_End_Date__c = conDate[i]; 
        }
    }
    
    if(instNotEmpty){
        update inst;
        instNotEmpty = false;
    }
}
-------------------------------------------------------------

My test class TestConTrig is:
@IsTest
//Account id='001w0000015qG3B'
//Installed_Asset__c='a06w000000eDn0O'

public class TestConTrig {
    static testMethod void validateTrig(){
        
        //Account ac = new Account(id='0011100000tx1kf');
        //System.debug('Account id is: ' + ac.Id);
        
        Account acc = new Account(Name = 'Covance', Phone = '63410741', CurrencyIsoCode = 'SGD', Type = 'Direct Customers', Industry = 'Industry & Material', Industry_Sub_Segment__c = 'Others');
        insert(acc);
        Contact ctc = new Contact(Account = acc, LastName = 'Gordon', CurrencyIsoCode = 'SGD', Phone = '63410741');
        insert(ctc);
        Installed_Asset__c asset = new Installed_Asset__c(Account_Name__c = acc.Id, Name = 'IN00253', Contact__c = ctc.Id, Install_Asset_Name__c = 'Freezer', Extension_Of_Warranty_In_Days__c = 0, Manufacturer_Info__c = 'Imported', Product_Line__c = 'AQI - GA');
        insert(asset);
        Contract cont = new Contract(AccountId = acc.Id, Installed_Asset__c = asset.Id,Status = 'Draft', StartDate=date.parse('02/02/2015'), contractTerm=12, Contract_Type__c='AMC');
        
        Account acc1 = new Account(Name = 'Covance', Phone = '12345678', CurrencyIsoCode = 'SGD', Type = 'Direct Customers', Industry = 'Industry & Material', Industry_Sub_Segment__c = 'Others' );
        insert(acc1);
        Contact ctc1 = new Contact(Account = acc1, LastName = 'Gordon', CurrencyIsoCode = 'SGD', Phone = '12345678');
        insert(ctc1);
        Installed_Asset__c asset1 = new Installed_Asset__c(Account_Name__c = acc1.Id, Name = 'IN00253', Contact__c = ctc1.Id, Install_Asset_Name__c = 'Freezer', Extension_Of_Warranty_In_Days__c = 0, Manufacturer_Info__c = 'Imported', Product_Line__c = 'AQI - GA');
        insert(asset1);
        Contract cont1 = new Contract(AccountId = acc1.Id, Installed_Asset__c = asset1.Id,Status = 'Draft', StartDate=date.parse('03/03/2015'), contractTerm=12, Contract_Type__c='CMC');
        
        insert(cont);
        insert(cont1);
        
        cont.put('Status','Activated');
        cont1.put('Status','Activated');
        
        update(cont);
        
        List<Installed_Asset__c> instAs = [SELECT id, AMC_End_Date__c, CMC_End_Date__c FROM Installed_Asset__c WHERE id =:cont.Id];
        
        if(instAs.size()==1){
            System.assertEquals(date.parse('02/02/2016'), instAs[0].AMC_End_Date__c);
        }
        
        update(cont1);
        
        List<Installed_Asset__c> instAs1 = [SELECT id, AMC_End_Date__c, CMC_End_Date__c FROM Installed_Asset__c WHERE id =:cont1.Id];
        
        if(instAs.size()==1){
            System.assertEquals(date.parse('03/03/2016'), instAs[0].CMC_End_Date__c);
        }
        
    }
}
---------------------------------------------
Keyur  ModiKeyur Modi
Hi,
whenver we used to deploy or validate the changeset it will run all the test class.
For Example if i created one workflow and one custom field in the sandbox and if i triy to move it to deployment at that time it will run all the test classes, so validation or deployment test class execution will be for all it will not related to component,

second question is the issue with validation error.

"0 0 TestCaseEscalationAndOthers.CaseEscalationTest(), Details: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Please enter the Phone Number (Format : Std Code-Phone Number): [Phone] Class.TestCaseEscalationAndOthers.CaseEscalationTest: line 8, column 1'

if we see the this error where highlighted part is main issue. so in that it clearly defined that one custom validation is there , having error "please enter phone Number(format :std Code-Phone Number).
please check the list of validations in your production instance. you can serach validaiton based on error message.

now if we see the second error

"FIELD_CUSTOM_VALIDATION_EXCEPTION, Contact does not belong to the specified Account: [ContactId] Class.updateCasesAfter60Mins.UpdateOpenCases: line 18, column 1 "

so this error again comming from the custom validation so please check it once the list of validations.

So, if you deactivate thoes two validaiton from prodution instace and try to validate it . you will not get any error.


Please let me know if this will help you,

Thanks,
Keyur Modi
 
This was selected as the best answer
Benjamin LeeBenjamin Lee
Hi Keyur,

Many thanks, I seem to be getting closer to the solution.
I was able to shut off the Phone number validation but not Account-Contact validation:

I am now receiving the following error:
User-added image

The invoking code is as follows:

@istest
 global static void testSchedule()
    {
   Test.startTest();

     Account NewAccount = new Account(Name = 'Test Account', Phone = 65-63410741);
     insert NewAccount;

     Contact NewContact = new Contact(Account=NewAccount, LastName = 'Jolly Test');
     insert NewContact;

     Installed_Asset__c ia=new Installed_Asset__c(name='TEST1', Install_Asset_Name__c='Install',  Account_Name__c=NewAccount.Id, Contact__c=NewContact.id);
     insert   ia;

     Case caseNewq = new Case(Product_Specialist_Count_of_Holidays__c=null,Installed_Asset__c=ia.Id, Status='New', Account=NewAccount.Id, Contact=NewContact.id, Count_of_Holidays__c=null,Product_Specialist_Last_Holiday_Date__c=(system.today()-1),Product_Specialist_Assigned_Date__c=system.today());
     insert caseNewq;

     Case caseNewq1 = new Case(Product_Specialist_Count_of_Holidays__c=0,Installed_Asset__c=ia.Id, Status='New', Account=NewAccount.Id, Contact=NewContact.id, Count_of_Holidays__c=0,Product_Specialist_Last_Holiday_Date__c=(system.today()-1),Product_Specialist_Assigned_Date__c=system.today());
     insert caseNewq1;


So far they all look linked and correct, I simply cannot figure out how is it violating the Account-Contact mis-match.
Whats more, sandbox produces absolutely no errors
User-added image

The test codes makes no reference to specific Ids, everything is created during test.
I do not see why it should fail.

Do you have any more suggestions?

Many thanks
Ben
 
Keyur  ModiKeyur Modi
Hi,
if we see the code which you mention in the above comment, where i think you need to do little modification for the  contact insertion
   in place of

Contact NewContact = new Contact(Account=NewAccount, LastName = 'Jolly Test');
     insert NewContact;

you need to use below code .. will insert contact below the account "Test Account"1

Contact NewContact = new Contact(AccountId=NewAccount.id, LastName = 'Jolly Test');
   insert NewContact;

please let me know if this will help,

Thanks,
Keyur Modi
Benjamin LeeBenjamin Lee
Hi Keyur,

It turns out that there were data anomaly in my production and because a separate class
TestCaseEscalationAndOthers.CaseEscalationTest: line 8, column 1' called for a query on all the cases in production, those anomalies were caught and produced non matching Account and Contact errors.

The production is already very mature to clear out all data anomaly, so I cleared out the offending test lines.
Salesforce needs to be more clear about their developing requirements.
It wasn't until you said that all components in production will be tested even though they are not deployed at the current changeset, that I realised I have to clear out existing problems
I also found out later that you cannot delete existing test classes using the web interface, it has to be done with Force.com IDE or ANT migration.
This was really frustrating if they do not specify upfront.

Thanks for all the help