+ Start a Discussion
Mustafa JhabuawalaMustafa Jhabuawala 

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

Hi,

This was working perfectly fine from past so many months and suddenly 2 days back this started throwing an error while executing test classes.

Code to execute
List<Contact> listContact = ContactTestDataFactory.createContact(1, 'FirstName', 'LastName'); insert listContact;

ContactTestDataFactory Test Class -
//Create Contact object 
public static List<Contact> createContact(Integer no_of_contact,String FirstName, String LastName){ 

List<String> lstSalutation = new List<String>{'Mr.','Ms.','Mrs.','Miss.','Dr.','U.S. Senator','U.S. Representative','Governor','Governor’s Cabinet Secretaries','Attorney General','State Senator','State Representative','Judge','Mayor','Consul-General','Ambassador','Ambassador to the U.S.','President of a Country','Former President','Lady','Police Chief','Chief Marshal','Dean','Professor','Priest','Pastor','Monsignor','Cantor','Rabbi','Nun or Sister','Brother','Bishop','Cardinal','Swami'}; 

List<Contact> listContact= new List<Contact>(); Contact objCon = new Contact(); 

for(Integer i=0;i<no_of_contact ;i++){ 
objCon = new Contact(); 
objCon.FirstName= FirstName; 
objCon.LastName= LastName; 
objCon.Salutation= lstSalutation[i]; objCon.Giving_Status__c= 'Prospect'; objCon.npe01__Primary_Address_Type__c = 'Residence'; objCon.MailingStreet = 'test'+i; 
objCon.Street_2__c = 'test 2'+i; objCon.MailingState='test'+i; objCon.MailingCity='test'+i; objCon.MailingCountry='test'+i; 
objCon.Gender__c = 'Female'; 
objCon.FirstName= FirstName; if(i/2 == 0){ objCon.Gender__c= 'Male'; 
} 
else{ 
objCon.Gender__c= 'Female'; 
} 
objCon.Unique_ID__c = String.valueOf(i); listContact.add(objCon); 
} 
System.debug('listContact'+listContact); 
return listContact; 
}

ERROR thrown - 
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, npsp.TDTM_Contact: execution of AfterInsert

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

(npsp)






: []

Any help would be really really appreciated.

I checked other post from Stackexcahnge as well and tried work around but no luck yet.
Stack excahnge similar issue link - https://salesforce.stackexchange.com/questions/79799/how-to-debug-the-mysterious-duplicate-value-found-unknown-duplicates-value-o


--
Kind Regards
Mustafa
Ash IshAsh Ish
Hi Mustafa,

06. List<Contact> listContact= new List<Contact>(); Contact objCon = new Contact();
09. objCon = new Contact();

Why double instantiation? Please do this at one place only.
Thanks.


 
Mustafa JhabuawalaMustafa Jhabuawala
Already tried that.

There is no such impact due to this code. Executed & verified too.
 
Ash IshAsh Ish
Why double assignment?

10. objCon.FirstName= FirstName;
15. objCon.FirstName= FirstName;
 
Mustafa JhabuawalaMustafa Jhabuawala
Unfortunately that's a client code.

Tried removing all such double assignments already. Not working yet.
Ash IshAsh Ish
Mustafa,

1. Is there any Account Object connection with this? If yes try creating separate Account test data.

2. If not, then try fixing this line of code.
    objCon.Unique_ID__c = String.valueOf(i); 

try any other workaround for this unique field. like changing value for assignment.
Thanks
Ashish Ranjan 

 
Rohit TantiRohit Tanti
Hindi status /new whatsapp status in hindi (https://newstatus.in/sad-status-hindi/)
KuldeepNegiKuldeepNegi
The Error seems to be from trigger in NPSP pack. Is there any dupicate management rule on Contact and any new fmatching criteria added to it.
Inspire DogsInspire Dogs
crate training of dogs (https://inspiredogs.com/crate-train-a-puppy-the-smart-way/) is so easy with proper training methods to keep dog inside the crate