I've a test class for a controller which passes in the development Org but not in the destination/sandbox. Here's the error I get
System.DmlException: Insert failed. First exception on row 0; first error: DUPLICATE_VALUE, duplicate value found: unknown duplicates value on record with id: a2u************: []
Now, there is an External Id - unique field in the Object that I create in the test class which I believe is the problem maker here. I've used Datetime.now()
to create a unique Id.
Datetime dt = Datetime.now();
String uniqueId = String.valueOf( dt.getTime() );
Sobject testObject = (sObject) Type.forName('My_Object__c').newInstance();
testObject.put('Custom_Name__c', 'TestLightning');
testObject.put('External_ID__c', 'TLHL' +uniqueId);
testObject.put('Reference__c', referenceId);
testObject.put('Asset__c', testAsset.Id);
insert testObject;
I've queried the existing data as well and I don't see any matching records or even the format I use for the unique field.
Disclaimer : I also have (SeeAllData=true)
annotation since I've used Chatter Api to post feeds in the controller and I cannot remove the annotation. I understand this complicates things by getting to see the existing records in the environment.
UPDATE: I've removed the External_Id__c since it was not a required field but ended up getting even more vague error.
APP_Name: duplicate value found: unknown duplicates value on record with id: unknown
Also, I tried removing the history tracking for an object which I believe might be a problem as pointed here but I can't do that as well since I need feed tracking enabled on the object, the controller logic posts in chatter and this needs to be enabled during deployment(learnt it with a failed upload obviously).
I've also came across this but I don't get any line number as mentioned in the post.
Anything I should look into? Am I missing anything obvious?
Thanks in advance! Peace!