Increasingly getting "DUPLICATE_VALUE" errors deploying

Issue #486 wontfix
Alex Jung created an issue

It appears that I sometimes get the following error saving code to a connected server:

e.g., 4:42 PM Deployment Failed: DUPLICATE_VALUE - duplicate value found: <unknown> duplicates value on record with id: <unknown>

Annecdotally, I seem to only get them with Apex Classes, but once I get them, I can no longer deploy the files for which I received the error.

Copy/pasting the code into the Developer Console and saving that way returns no errors and I'm able to save successfully.

Using 1.7.5.7 of IlluminatedCloud Using IDEA 2016.3 (163.7743.44, built 11/17/2016) Host OS: Mac OS X 10.12.1

Comments (17)

  1. Scott Wells repo owner

    Alex, would you mind capturing some debug logs for me? Please add the following under Help>Debug Log Settings:

    #com.illuminatedcloud.intellij.builder.ForceComBuilder
    #com.illuminatedcloud.intellij.builder.ForceComToolingApiDeployer
    #com.illuminatedcloud.intellij.builder.ForceComMetadataApiDeployer
    

    When you get this issue, please send me the idea.log using Help>Show Log in Finder.

  2. Scott Wells repo owner

    Thanks, Alex. So you're getting the error because IC is incorrectly deciding that it needs to create the class. Would you do me a favor and run the following SOQL query in Developer Console with Use Tooling API checked?

    SELECT Id, Name, ManageableState
    FROM ApexClass
    WHERE Name = 'ContactTriggerHandler'
    AND ManageableState NOT IN ('deleted', 'installed')
    

    I'd like to see the results. Thanks!

  3. Alex Jung reporter

    Hmmm... I get 0 rows/results for the above query AND when the query modified by removing the "ManageableState NOT IN..." clause.

  4. Alex Jung reporter

    And even odder, removing the entire "Where" clause actually brings it back in the result set.

    adding the "name" where clause back after copy/pasting 'ContactTriggerHandler' from the result set that worked brings back 0 records...

  5. Scott Wells repo owner

    Okay, so that's why this is happening. Do you mind providing the rows that are returned when you remove the constraint on ManageableState from the WHERE clause? I'd like to see what the manageable state is reported to be.

  6. Alex Jung reporter

    Trying to figure out a good way to "export" the data. Short term, all returned rows have 'unmanaged' for ManageableState.

  7. Scott Wells repo owner

    Thanks, Alex. Would you mind running this specific query:

    SELECT Id, Name, ManageableState
    FROM ApexClass
    WHERE Name = 'ContactTriggerHandler'
    

    and providing the results?

  8. Alex Jung reporter

    how odd! with the where clause, it returns 0 results...

    I've also played with some "like" clauses...

    SELECT Id, Name, ManageableState
    FROM ApexClass
    WHERE Name like '%Contact%'
    

    brings back the class (and of course, several others)

    but any more selective "like" clauses (where I progressively add letters) do not include ContactTriggerHandler:

    SELECT Id, Name, ManageableState
    FROM ApexClass
    WHERE Name like '%ContactT%' 
    

    But brings back the similarly named 'ContactTriggerHandler_Test' class

  9. Alex Jung reporter

    And sorry, i need to step away, but can be back online in about an hour, if you want me to provide any further details...

  10. Scott Wells repo owner

    Okay, so that's the problem, and I agree that it's very odd. Basically I decide whether to create or update based on whether metadata of the same type already exists in the org with the same name and a mangeable state other than installed (from managed package) or deleted. In this case, the query is returning zero rows, so I'm deciding the create the class.

    I'm not 100% sure what to do about this. I have some suggestions, but something definitely looks odd with your metadata in Salesforce, and I fear it may manifest in less benign ways.

    One suggestion would be to undeploy the metadata from the org if you're able to do so, then re-deploy it to see if it corrects the situation. IC does support bulk undeploy, so you should be able to right-click on the things you want to remove/redeploy (and anything that refers to them transitively), remove them from the org, and then re-add them. Hopefully that will make things right.

    Another suggestion would be to open a support case with Salesforce leading with the fact that you can't query the class by name or even semi-selective pattern, then see if they can determine the root cause of the issue.

    I'm happy to keep looking at this with you, but at this point the behavior is so odd that I'm concerned about the integrity of the metadata in the org. Just let me know what you'd like to do next...

  11. Scott Wells repo owner

    Alex, is there anything else you'd like for me to do on this issue? If not I'd like to resolve it as "won't fix" since it seems to be based on odd behavior in the server.

  12. Alex Jung reporter

    Thanks for following up Scott,

    Yes, please feel free to close. I have an open ticket with SF to discuss this. It probably won't be resolved for a bit since I have a series of demos for clients/end-users but I think this is something only SF can fix.

    Out of curiosity, how does one undeploy using IC? You probably have a FAQ or something :), but I was actually trying to find that bit of functionality in Intellij and couldn't find it...

  13. Scott Wells repo owner

    Alex, there's a Delete Metadata option right alongside Retrieve/Refresh/Deploy Metadata in IC. That's an undeploy from the server. Just select the things you want to undeploy and it'll generate a destructiveChanges.xml for you and run it. Let me know if that doesn't get you there.

  14. Scott Wells repo owner

    Seems to be an odd issue on the server outside of IC's purview. If it does turn out after speaking with Salesforce that there's something I can do to resolve/accommodate for this, feel free to reopen with the relevant info.

  15. Log in to comment