function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
prasanth sfdcprasanth sfdc 

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

Hi, 
 I have custom field called Email__c and marked it as Unique . 
When i insert lead using some apex logic with duplicate Email__c then it shows error in debug log like 
 
duplicate value found: Email__c duplicates value on record with id: 00Q1700000DfdUO;

But when insert the duplicate lead from test calss then giving the below output. 
 
duplicate value found: <unknown> duplicates value on record with id: <unknown>;

How to get Email__c in the place of "<unknown>" in test class. Please help. Due to this i am not able to cover some lines of code. 

Main class code here. 
in the below code not enteringing into if statement because of "<unknown>" is coming instead of "Email__c"
for (Database.Error dbE : errorList) {
            //handle duplicate applicant
            system.debug('the sai 1st outside:'+dbE+'....'+dbE.getStatusCode()+'....'+System.StatusCode.DUPLICATE_VALUE);
            if((dbE.getStatusCode() == System.StatusCode.DUPLICATE_VALUE && dbE.getMessage().contains('Email__c') )) {
             system.debug('the sai 1st inside:'+dbE.getMessage());
                String dupId = dbE.getMessage();
                
                    dupId = dupId.substringAfter('Prospect_UUID__c duplicates value on record with id: ');
                
                errList.add(handleDuplicateUUIDApplicant(dupId, NULL, leadRec.Email__c));
            }

 
AbhinavAbhinav (Salesforce Developers) 
It seems challenging to get field name or object in that error based on discussion on below link:

https://salesforce.stackexchange.com/questions/79799/how-to-debug-the-mysterious-duplicate-value-found-unknown-duplicates-value-o