6

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.

9

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

  • 1
    Note that if this does work, we should try to get the documentation updated... – Robert Watson Oct 31 '17 at 16:43
  • 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 Nov 2 '17 at 10:49
  • 1
    I found a more useful page here and requested to have it updated. – Robert Watson Nov 2 '17 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 Feb 27 '19 at 15:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.