3

I'm attempting to validate an incoming changeset, and SFDC tells me that my Unit Test bails with the following error:

Failure Message: "System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, <script src="/js/functions.js" type="text/javascript"></script><script src="/soap/ajax/20.0/connection.js" type="text/javascript"></script><script src="/soap/ajax/20.0/apex.js" type="text/javascript"></...

In the verification results I get the following data, in addition to the above error:

UnitTests_CaseSendToTechnologyTeams.newCase()   Class   30  
UnitTests_CaseSendToTechnologyTeams.sendToHosting() Class   30
UnitTests_CaseSendToTechnologyTeams.sendToInnovation()  Class   30 

I am at a loss to understand where this error is being triggered.

@isTest
private class UnitTests_CaseSendToTechnologyTeams {
static Account myAccount = null; 
static Contact myContact= null; 

static private Account getAccount() { 
    if ( myAccount == null ) {
        myAccount = UnitTests_DataFactory.getAccount();
    } 
    return myAccount ; 
}

static private Contact getContact() { 
    if ( myContact == null ) { 
        Account a = getAccount(); 
        myContact = new contact(FirstName = 'Test', LastName = 'Contact', Email = '[email protected]');
        myContact .AccountId = a.Id;
        insert myContact ;
    }
    return myContact ;                  
}

static private Case newCase() { 
    RecordType suppRT = Case_DataFactory.getCaseSupportRecordType( Case_DataFactory.RECORDTYPE_SUPPORT ); 

    Case c = new case(Subject = 'Test');
    c.Status = 'New';
    c.RecordTypeId = suppRT.Id;
    c.AccountId = getAccount().Id;
    c.ContactId = getContact().Id;
    c.Subject = 'Test Subject';
    c.Description = 'Test Description';
    insert c;

    c.Technical_Description__c = 'Test Technical Description';
    c.Origin = 'Support';
    c.Priority = 'Urgent';
    update c;
    c.Customer_Priority__c = 'Urgent';
    c.Reason = 'Other';
    c.Version__c = 'SL 5.3';
    c.Service_Pack__c = '5.3.8';
    update c; 
    c.System_Impacted__c = 'Production System';
    c.Build_Number__c = '';
    c.OperatingSystem__c = 'RedHat Linux';
    c.Problem_Area__c = '';
    c.Product_Component__c = '';
    c.Request_Type__c = '';
    update c;

    return c;
}

static testMethod void sendToServices() {
    System.runAs( UnitTests_DataFactory.getRandomSupportUser() ) {
        Case c = newCase(); 

        c.WizardAction__c = 'SendToTechTeam';
        c.Technology_Team__c = 'Services';
        update c;
    }
} 

static testMethod void sendToHosting() { 
    System.runAs( UnitTests_DataFactory.getRandomSupportUser() ) {
        Case c = newCase(); 
        c.WizardAction__c = 'SendToTechTeam';
        c.Technology_Team__c = 'Hosting';
        update c;
    }
}

static testMethod void sendToRnD() { 
    System.runAs( UnitTests_DataFactory.getRandomSupportUser() ) {
        Case c = newCase();     
        c.WizardAction__c = 'SendToTechTeam';
        c.Technology_Team__c = 'R&D';
        update c;
    }
}

static testMethod void sendToProdMgmt() { 
    System.runAs( UnitTests_DataFactory.getRandomSupportUser() ) {
        Case c = newCase();     
        c.WizardAction__c = 'SendToTechTeam';
        c.Technology_Team__c = 'Product Management';
        update c;
    }   
} 

static testMethod void sendToInnovation() { 
    System.runAs( UnitTests_DataFactory.getRandomSupportUser() ) {
        Case c = newCase();     
        c.WizardAction__c = 'SendToTechTeam';
        c.Technology_Team__c = 'Innovation';
        update c;
    }
}
}

UnitTests_DataFactory.getAccount is:

static public Account getAccount() { 
    list<Account> accs = [SELECT Id, Name FROM Account where Name = 'MyAccount'];
    System.assert(accs.size() <= 1, 'Too Many \'MyAccount\' Accounts are present in test data. ');
    if (accs.size() == 1 )  return accs.get(0);

    Account myAccount= new Account(); 
    myAccount.Name = 'MyAccount'; 
    insert myAccount; 
    return myAccount;
}

When I run in the Force.com IDE - No issues. This almost looks like what I would expect from a failure with VisualForce pages - is it possible one of my third party packages is causing this (I have RippleFly installed, as well as others like LinkedIn). And how the hell do I find out where it's coming from? This is all the error messages I get from SFDC - I'm not sure how to get more extensive logging like I do from the Force.com IDE.

Is this something I can get better information from if I use the Migration Tool?

1 Answer 1

1

It appears there is a Validation Rule on the object that you are trying to insert to which is causing the exception (FIELD_CUSTOM_VALIDATION_EXCEPTION).

  1. Find the Validation Rule that's causing the trouble

  2. Either (a) fix your code so that it honors the Validation Rule or (b) turn off the Validation Rule to get your code to deploy, then run your test code in Production to try to debug the problem further (since you can't replicate the issue in the Sandbox).

You'll want to re-activate the Validation Rule, I'm sure, so you'll still have to do (a) at some point.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .