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
Michael Clarke 16Michael Clarke 16 

Auto Convert Lead error

Hi, I am new to salesforce code.
I am building an Auto Convert Lead process when LeadSource = 'Web' and Rating = 'Hot'.
I have written the Apex Code (I will bulikfy it when it works and I fully understand the process) and a Test Class which runs successfully.
I have a Process Bulder that kicks it off. (passes through LeadIds = Lead.Id)
User-added imageApex Code:
Public class AutoConvertLeads
{
    @InvocableMethod
    public static void LeadAssign(List<Id> LeadIds)
    {
        system.debug('1');
        Database.LeadConvert leadConvert = new Database.LeadConvert();
        system.debug('2');
        leadConvert.setLeadId(LeadIds[0]);

        system.debug('3');
        LeadStatus LeadStat= [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];

        system.debug('4');
        leadConvert.setConvertedStatus(LeadStat.MasterLabel);
        //Leadconvert.setDoNotCreateOpportunity(TRUE); //Remove this line if you want to   create an opportunity from Lead Conversion 

        system.debug('5');
        Database.LeadConvertResult lcr = Database.ConvertLead(leadConvert);
        system.debug('6');
        System.assert(lcr.isSuccess());
        system.debug('7');
    }
}

Test Class:
@isTest
private class AutoConvertLeadsTest {

    @isTest static void testLeadConversion() {
        Lead Ld = new Lead();
        Ld.FirstName = 'TestFirstName';
        Ld.LastName = 'TestLastName';
        Ld.Company = 'TestCompany';
        Ld.LeadSource = 'Web';
        Ld.Rating = 'Warm';
        Ld.Status = 'Open - Not Contacted';
        Ld.Email = 'test@testdwr.com.zz';
        system.debug('a');
        insert Ld;
        system.debug('b');
        Ld.Rating = 'Hot';
        update Ld;
        system.debug('c');

    }
}

When I edit the LeadSource = 'Web' and Rating = 'Hot' on the UI it kicks off the Process and then Apex code.
I get the following error:
Review the errors on this page.
We can't save this record because the “Auto Convert Lead” process failed. Give your Salesforce admin these details. An Apex error occurred: System.DmlException: ConvertLead failed. First exception on row 0; first error: DUPLICATES_DETECTED, Use one of these records?: [] Error ID: 839700365-14885 (-1370628323)


I am mystified what the source of the error is.
Hoping you can help me.
Michael Clarke 16Michael Clarke 16
Here is the error msg I received via email:
Error element myRule_1_A1 (FlowActionCall).
An Apex error occurred: System.DmlException: ConvertLead failed. First exception on row 0; first error: DUPLICATES_DETECTED, Use one of these records?: []

Flow Details
Flow API Name: Auto_Convert_Lead
Type: Record Change Process
Version: 2
Status: Active
Org: Consulting Consultants and Associates (00D0o000001QVdS)

Flow Interview Details
Interview Label: Auto_Convert_Lead-2_InterviewLabel
Current User: Michael Clarke (0050o00000X3xqq)
Start time: 30/07/2020 11:39 AM
Duration: 1 seconds

How the Interview Started
Michael Clarke (0050o00000X3xqq) started the flow interview.
Some of this flow's variables were set when the interview started.
myVariable_old = Lead (00Q0o00001e8sZcEAI)
myVariable_current = Lead (00Q0o00001e8sZcEAI)

DECISION: myDecision
Outcome executed: myRule_1
Outcome conditions:
1. {!myVariable_current.Rating} (Hot) Equals Hot
2. {!myVariable_current.LeadSource} (Web) Equals Web
Logic: All conditions must be true (AND)

AUTOCONVERTLEADS (APEX): myRule_1_A1
Inputs:
LeadIds = {!myVariable_current.Id} (00Q0o00001e8sZcEAI)

Error Occurred: An Apex error occurred: System.DmlException: ConvertLead failed. First exception on row 0; first error: DUPLICATES_DETECTED, Use one of these records?: []


Salesforce Error ID: 839700365-14885 (-1370628323)
Trung Hieu Tran 5Trung Hieu Tran 5
Have you found the solution for this one ? Because I have the same issue like the one you have