[SalesForce] Bypass duplicate when converting a lead

I'm trying to convert a lead to a contact, the lead has the same email than another contact, but I want to create a new contact. when I try to convert the lead, I got an error 'DUPLICATES_DETECTED :
A contact with the same email address exists. Do you want to continue'.

And the lead is not converted.

It seems that the conversion is done with

Database.LeadConvert lc = new database.LeadConvert();
//some parameters are set here
Database.LeadConvertResult lcr = Database.convertLead(lc);

when I have to bypass duplicates when I'm trying to do an insert, I use something like that :

Database.DMLOptions dml = new Database.DMLOptions();
dml.DuplicateRuleHeader.AllowSave = true;
Databsae.SaveResult sr2 = Database.insert(account, dml);

But in the case of a lead conversion I don't know if it is possible.
I know there is a checkbox in the parameters of the lead in the admin part of salesforce, but this option does not do what I want, so I can't use that. I just want to bypass the duplicates.

Best Answer

I have yet to find official documentation on this, but the Database.convertLead method actually accepts a second parameter, an instance of Database.DMLOptions. So I believe you should be able to do something like:

Database.LeadConvert lc = new Database.LeadConvert();
//some parameters are set here
Database.DMLOptions dml = new Database.DMLOptions();
dml.DuplicateRuleHeader.AllowSave = true;
Database.LeadConvertResult lcr = Database.convertLead(lc, dml);

Source: the OfflineSymbolTable in IntelliJ/Illuminated Cloud

Related Topic