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
Sandeep Rahul PVSandeep Rahul PV 

Getting This Error While Validating in Production during Production "System.DmlException: ConvertLead failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Your lead is missing a field mapping for the fields. For help, talk with your adm"

My Code:

Apex Class:
--------------------

public class LookupApexAuraServices {
@AuraEnabled
    public static List<Lead> ChooseExistingAcc(string leadId, string accountId){
        List<Lead> convertedList = new List<Lead>();
        Database.LeadConvert lc = new Database.LeadConvert();
        lc.setLeadId(leadId);
        lc.setAccountId(accountId);
        lc.setDoNotCreateOpportunity(true);
        LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
        lc.setConvertedStatus(convertStatus.MasterLabel);
        Database.LeadConvertResult lcr = Database.convertLead(lc);
        convertedList = [SELECT Id, Name, RecordTypeId, 
                         IsConverted, ConvertedAccountId, ConvertedContactId 
                         FROM Lead where id =:leadId limit 1];
        system.debug('convertedList : '+convertedList);
        return convertedList;
    }
}

Test Class:
------------------
@IsTest
public class LookupApexAuraServices_Test {
    private class RestMock implements HttpCalloutMock {
        public HTTPResponse respond(HTTPRequest req) {
            String fullJson = 'your Json Response';
            
            HTTPResponse res = new HTTPResponse();
            res.setHeader('Content-Type', 'text/json');
            res.setBody(fullJson);
            res.setStatusCode(200);
            return res;
        }
    }
static testmethod void testChooseExistingAcc(){
        Id devRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Person Account').getRecordTypeId();
        List<Account> acclist = new List<Account>();
        Account a = new Account();
        a.RecordTypeId = devRecordTypeId;
        a.FirstName = 'Accfname';
        a.LastName = 'AccTestLName';
        acclist.add(a);
        insert acclist;
        List<Lead> leadlst = new List<Lead>();
        lead l = new lead();
        l.FirstName = 'testf';
        l.LastName = 'testlast';
        l.Email = 'asdfg@gmail.com';
        leadlst.add(l);
        lead ld = new lead();
        ld.FirstName = 'testfirst';
        ld.LastName = 'testlast';
        ld.Email = 'asdf@gmail.com';
        leadlst.add(ld);
        insert leadlst;
        Test.startTest();
        Test.setMock(HttpCalloutMock.class, new RestMock());
        LookupApexAuraServices.ChooseExistingAcc(ld.Id, a.Id);
        Test.stopTest();
    }
}
Code COverage is 95% but while deployment getting this error
Getting This Error While Validating in Production during Production "System.DmlException: ConvertLead failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Your lead is missing a field mapping for the fields. For help, talk with your admin" ....?
User-added imagePlease Help Me guys.

ravi soniravi soni
hi,
try below code,
public static List<Lead> ChooseExistingAcc(string leadId, string accountId){
        List<Lead> convertedList = new List<Lead>();
        Database.LeadConvert lc = new Database.LeadConvert();
		
        lc.setLeadId(leadId);
        lc.setAccountId(accountId);
        lc.setDoNotCreateOpportunity(true);
        LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
        lc.setConvertedStatus(convertStatus.MasterLabel);
        Database.LeadConvertResult lcr = Database.convertLead(lc, false);
        convertedList = [SELECT Id, Name, RecordTypeId, 
                         IsConverted, ConvertedAccountId, ConvertedContactId 
                         FROM Lead where id =:leadId limit 1];
        system.debug('convertedList : '+convertedList);
        return convertedList;
    }

Make sure mapping is good.
you can take reference from below link about lead mapping.
https://help.salesforce.com/s/articleView?id=sf.customize_mapleads.htm&type=5

if above info is helpful to you ,don't forget to mark it as best answer.
Thank you
ravi soniravi soni
Please Close your Query By Marking It As Best Answer If It Helps So it Also helps Others in Future
Thank You!