You need to sign in to do that
Don't have an account?
Samantha Catania
DUPLICATE_DETECTED Error when converting lead from APEX but not screen
When trying to convert a Lead using the standard APEX method we get a DUPLICATE_DETECTED error because there is another Lead with the same email address. The same behaviour is not experianced with the exact same Lead when converting using the convert button on the screen.
Error Message:
System.DmlException: ConvertLead failed. First exception on row 0; first error: DUPLICATES_DETECTED, You're creating a duplicate contact. We recommend you use an existing record instead.: []
Apex Code (from SF Example in Doc (https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_dml_convertLead.htm))
Is this a bug in the out of the box method or am I missing something?
Error Message:
System.DmlException: ConvertLead failed. First exception on row 0; first error: DUPLICATES_DETECTED, You're creating a duplicate contact. We recommend you use an existing record instead.: []
Apex Code (from SF Example in Doc (https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_dml_convertLead.htm))
Database.LeadConvert lc = new Database.LeadConvert(); lc.setLeadId('00Q5t000003eBKzEAM'); lc.setConvertedStatus('Closed - Converted'); Database.LeadConvertResult lcr = Database.convertLead(lc);
Is this a bug in the out of the box method or am I missing something?
I think, the reason why you might not encounter this issue when converting the Lead using the standard Convert button on the screen is that Salesforce has built-in duplicate detection logic in the standard conversion process.
When you manually convert a Lead through the Salesforce UI, it performs additional checks and gives you options to merge or link the Lead with an existing Contact or Account if it finds potential duplicates.
However, when you are converting Leads programmatically using Apex code, you need to handle duplicate detection and resolution yourself. This means you should check for existing Contacts or Accounts with the same email address before attempting to convert the Lead.
Here's a modified version of your code that includes a check for duplicates and handles them :
Or if you have a dupliacate rules, you should try something like : => Specify the Duplicate Rule for Contacts (replace 'My_Duplicate_Rule_API_Name' with your rule's API name)
I hope this comment has helped you,
Julien