+ Start a Discussion

error while running test cases



I am getting error while running test cases.


System.DmlException: Insert failed. First exception on row 0; first error: DUPLICATE_VALUE, duplicate value found: <unknown> duplicates value on record with id: <unknown>


Please help me its urgent




It would help if you posted the code test method itself, but it looks like maybe you're trying to insert the same record twice.  If it's supposed to be the same record, the second operation needs to be an update and not an insert.  If you're trying to insert two separate records, but using the same variable for both, make sure you reset that variable completely using variable = new SObject(...).




I'm getting the exact same error. The same tests ran fine yesterday. I'm guessing something in the deploy last night broke the testrunner.


In our code, the exception is happening when inserting an account with the following code:



Account acct = new Account(); acct.Name = 'Test Household ' + uniqueValue; acct.Phone = '123'; acct.RecordTypeId = Utils.getRecordTypeId(Constants.householdRecordType); insert acct;


 There shouldn't be any unique attributes on the account.



Please see response from SF Support:

"Thank you for your inquiry.  This error is the result of a bug that incorrectly uses an autonumber field.  While we do not provide guaranteed timelines for bug fixes, this is expected to be fixed within the coming week.  In the meantime, avoid using the DML insert statement in test methods.  One workaround would be to query data and perform an update.  Test methods do not commit data, so the update will not actually affect the queried data."