9

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.

1 Answer 1

19

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

5
  • 2
    Note that if this does work, we should try to get the documentation updated... Commented Oct 31, 2017 at 16:43
  • 2
    Thank you a lot, I thought that the Database.DMLOptions would not work since it is not specified in the documentation, but it works very well ! And as you point it out, maybe the documentation should be updated...
    – dou
    Commented Nov 2, 2017 at 10:49
  • 2
    I found a more useful page here and requested to have it updated. Commented Nov 2, 2017 at 18:14
  • this is not working for me. adding the dmloptions parameter causes lead conversion to skip the warning / not display the alert, but the lead conversion fails. this doc appears to indicate that all lead conversion will fail unless you turn off 'require validation for converted leads'. still poking on this.
    – gorav
    Commented Feb 27, 2019 at 15:51
  • Thank you!! I wish I had found this solution sooner. It works perfectly to resolve the duplicates error on lead conversion and only requires a couple lines of code.
    – Anika
    Commented Sep 18, 2020 at 20:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .