6

After wasting an entire day attempting to deploy a huge release to production I'm graveling at the feet of the Salesforce community. So many issues when attempting to package my release (including classes, objects, layouts, pages, triggers and of course my package.xml). Issues where it would say the vf_custom.page could not reference the vf_controller.cls because it did not exist even though it was in the manifest and in the zip. :(

But I digress. Since then I've attempted to try small chunks, but even still I have constant issues. Once being that I cannot even re-deploy test classes that are already in production because since: Summer '15 - API Status Code Changes I now get DUPLICATE_VALUE, duplicate value found

I even re-ran my class currently in production and it failed to pass now because of this error.

Essentially I have a test class for each object that begins like so:

@testSetup public static void virtualSandbox() {
    TriggerHandler.bypass('AccountTriggerHandler');
    TriggerHandler.bypass('ContactTriggerHandler');

    List<Account> accounts = createAccounts(); INSERT accounts;
    List<Contact> contacts = ContactTest.createContacts(); INSERT contacts;

    TriggerHandler.clearBypass('AccountTriggerHandler');
    TriggerHandler.clearBypass('ContactTriggerHandler');
}

This creates the data that the @isTest methods then use. Because of this change my first @isTest method (which INSERTS the object this time within the test context), began breaking in the sandbox during development. No big deal I realized the issue was that my test was reinserting what my @testSetup method already setup. Was never an issue before but it is now. Not a problem, for this test I will delete the accounts before I re-insert them within my Test.startTest() context like so:

@isTest public static void insertAccounts() {
    /* Avoid DUPLICATES_DETECTED error API status change #000214063 */
    List<Account> virtualAccounts = [SELECT Id FROM Account];
    DELETE virtualAccounts;

    List<Account> accounts = createAccounts();

    Test.startTest();
        INSERT accounts;
    Test.stopTest();

    System.assert(accounts[0].Id != null,'Accounts were INSERTED');
}

In sandbox this works perfectly. Unfortunately when I attempt to deploy this change to production it appears irrelevant and I continue to get issues. This is killing me and I need sleep so really hoping for some fresh eyes and suggestions for tomorrow. Thank you!

  • When you say you continue to get issues, what issues are you getting exactly? What does the createAccounts() method look like? – Rob Aug 28 '15 at 9:27
  • 3
    The accounts, etc will still exist that were created in @testSetup when you try to recreate them within your test method. That would seem to be the cause of your error. Those need to be maintained for use by other methods. At best case, I'd expect them to go to a "virtual" recycle bin where you'd need to undelete them as though you were testing an AfterDelete trigger. – crmprogdev Aug 28 '15 at 15:19
  • 1
    The createAccounts() method simple iterates 100 times over to create a List<Account>. This includes an Account with every picklist possibility and all record types, and all required fields. Thanks @crmprogdev makes sense I'll try that first thing this morning. – Xtremefaith Aug 28 '15 at 15:56
2

Apparently as suggested by @crmprogdev, there is in fact a "virtual recycle bin" that is keeping the deleted records so I just needed to remove them from the recycle bin like so:

@isTest public static void insertAccounts() {
    /* Avoid DUPLICATES_DETECTED error API status change KB Article: #000214063 */
    List<Account> virtualAccounts = [SELECT Id FROM Account];
    DELETE virtualAccounts;
    Database.emptyRecycleBin(virtualAccounts);

    List<Account> accounts = createAccounts();

    Test.startTest();
        INSERT accounts;
    Test.stopTest();

    System.assert(accounts[0].Id != null,'Accounts were INSERTED');
}
  • 2
    That's helpful to know, good thinking @crmprogdev and thanks for posting your solution Xtremefaith – Rob Aug 28 '15 at 17:36

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.