4

As many others have already done, I am providing yet another cautionary tale of the elusive, misleading, and downright frustrating, magical error:

duplicate value found: <unknown> duplicates value on record with id: <unknown>

The situation:

  • Attempting to deploy an Apex Class from my local IDE
  • Deployment fails, no error messages back whatsoever
  • Created the empty Apex Class directly in the Salesforce Developer Console
  • Pasted in content from local IDE
  • Attempted to save, gets back the magical error message in the Problems list
  • Searched online, everyone is saying one of the following:
    • It's version history on fields, turn it off, apparently this one is solved as of Winter '19 release
    • An update DML statement is violating some kind of uniqueness constraints.
  • Commented out class body, no effect
    • So the issue isn't update DML statements either.
  • Commented out superclass extend, no effect

I have posted the resolution I found below as an answer.

4

The Resolution!

It was a PEBKAC error. But since this is an extremely vague error, I figure I will throw my own experience out. The more instances of this that get thrown out, I figure everyone will have a better grasp of how wide a range, and also how simple an issue can be and still set off this completely erroneous message.

That's the main focus here, is that even if my particular situation doesn't apply, look for other things that are as stupidly simple as this.

In my case, this class I was trying to deploy was borrowed from another. Created the new Apex Class, copy-pasted contents from another, gutted specific parts from the original and replaced them with specific parts for the new.

You can probably already guess where this is going.

I forgot to change the name of the class at the top of the file.

So, the class, the file being named OpportunityHandler.cls, had the declaration inside of AccountHandler. Problem is two fold: Not only does the file name not match the class declaration it holds inside, but this is now a second file trying to declare the class of AccountHandler.

The fix? Change the class declaration to match the file name.

After this it's pretty clear why it was a warning about duplicates. It was a duplicate class declaration! It still doesn't help that the error is so vague for such a simple, avoidable, PEBKAC-induced issue like this. But more than anything I just want to throw another example out of what this duplicate warning can mean.

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.