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
Daniel GageDaniel Gage 

LeadConvert trigger is getting a Duplicate_Value error when set up as "after insert"

Help: First exception on row 1; first error: DUPLICATE_VALUE, duplicate value found:This is pretty much driving me crazy tonight. I have a Trigger that converts leads to Contacts based on criteria in another entity.

Below is the Lead Convert, which is failing with
LeadConvertVerified: execution of AfterInsert

caused by: System.DmlException: ConvertLead failed. First exception on row 1; first error: DUPLICATE_VALUE, duplicate value found: []

Trigger.LeadConvertVerified: line 30, column 1





The only thing is... I hve another trigger that is happening on "before insert". But it is working fine. The failure is happening during the conversion process. I have tried changing this to After Update.. but then it never runs, because nothing is updating it. (even though the Before Insert completes successfuly.)


If I change the below to "After Update" it will work when I manually update the lead. But I need it to convert during the bulk upload.


I have no idea what is happening and have spent too much time banging my head against the wall.


1. I am only loading 5 records as a test.
2. I have verified that the leads do not contain duplicate data for Organization__c or Company(Account).
4. There is no duplicate e-mail, etc...
5. Contacts with the same e-mails as the leads do not exist. 


Any help would be appreciated.


trigger LeadConvertVerified on Lead (after Insert) {
 
 
    LeadStatus convertStatus = [
        select MasterLabel
        from LeadStatus
        where IsConverted = true
        limit 1
        ];
List<Database.LeadConvert> leadConverts = new List<Database.LeadConvert>();


    for (Lead lead: Trigger.new) {
    
   if (!lead.isConverted && lead.Verified__c == True){
            
    Database.LeadConvert lc = new Database.LeadConvert();
    
    lc.setLeadId(lead.Id);
    lc.setAccountId(lead.Organization__c);
    lc.setDoNotCreateOpportunity(TRUE);
    lc.setConvertedStatus(convertStatus.MasterLabel);
    
    leadConverts.add(lc);

        }
    }
        
if (!leadConverts.isEmpty()) {
List<Database.LeadConvertResult> lcr = Database.convertLead(leadConverts);
}

        
}
 
Best Answer chosen by Daniel Gage
ShashankShashank (Salesforce Developers) 
Please check if the explanation in this article helps: https://help.salesforce.com/apex/HTViewSolution?urlname=duplicate-value-found-On-Lead-Conversion&language=en_US

All Answers

ShashankShashank (Salesforce Developers) 
Please check if the explanation in this article helps: https://help.salesforce.com/apex/HTViewSolution?urlname=duplicate-value-found-On-Lead-Conversion&language=en_US
This was selected as the best answer
Daniel GageDaniel Gage
Thank you... I'll look into that.. and it makes sense as the lead does have a few new fields, I'll have to double check the settings. I'll post a reply if I can't figure it out, and need further help. Thank you again.
 
Daniel GageDaniel Gage
Thank you. It was indeed a Unique Value field.. which was getting duplicate values inserted from the before insert trigger. Very much appreciate your help