My test class is failing and giving error as

System.DmlException: ConvertLead failed. First exception on row 0; first error: UNKNOWN_EXCEPTION, System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Category__c, SubCategory__c]: [Category__c, SubCategory__c] Class.leadconvert.BulkLeadConvert.handleOpportunityInserts: line 740, column 1 Class.leadconvert.BulkLeadConvert.convertLead: line 104, column 1: [] Stack Trace: Class.ContractViaOpportunityTrgTest.myUnitTest1: line 193, column 1 "

On opportunity object i have Subcategory and category as required fields.

Below is mt test class code-

private class ContractViaOpportunityTrgTest{

static testMethod void myUnitTest1()
        Language_Templates__c language = [Select id from Language_Templates__c where Name = 'English' limit 1];
        Regional_Operating_Parameters__c testRegion = new Regional_Operating_Parameters__c(name='test', Region_name__c='testRegion');
        insert testRegion;
        Lead testLead = new Lead();
        testLead.FirstName = 'Test First';
        testLead.LastName = 'Test Last';
        testLead.Company = 'Test Co';
        testLead.language__c = language.id;
        insert testLead;

        Database.LeadConvert lc = new Database.LeadConvert();

        LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];

        Database.LeadConvertResult lcr = Database.convertLead(lc);

        Regional_Operating_Parameters__c RegOpParameter = new Regional_Operating_Parameters__c(Name='United Kingdom',Region_name__c='United Kingdom',Country_Code__c='UK');
        insert RegOpParameter;

        Account accountObj = new Account(Name='TestAccount', Region__c = RegOpParameter.Id);
        insert accountObj;

        Account accountObjTst = new Account(Name='TestAccount');
        insert accountObjTst;        


        Opportunity OppObjTst = new Opportunity();
        OppObjTst.Name = 'Test Opportunity1';
        OppObjTst.StageName = 'Prospecting';
        OppObjTst.Probability = 50;     
        OppObjTst.AccountId = accountObjTst.Id;
        OppObjTst.Contract_Term_months__c = 20;
        OppObjTst.CloseDate = System.today()+1;
        OppObjTst.Invoice_Date__c  = System.today();        
        OppObjTst.Contract_Start_Date__c = System.today().addMonths(10);
        OppObjTst.Existing_Contract__c = true;
        OppObjTst.New_Contract__c =false;
        OppObjTst.Forecast_Needed__c = true;

        insert OppObjTst;

        OppObjTst.Contract_Start_Date__c = System.today().addMonths(27);
        update OppObjTst;   

Can you please help me how to fix this issue in

Class.leadconvert.BulkLeadConvert.handleOpportunityInserts: line 740, column 1 Class.leadconvert.BulkLeadConvert.convertLead: line 104, column 1: []

Lead convert class-

trigger AutoConvertLead on Lead (after insert) {
    //Declaring variables
    list<Lead> LeadObjList = new list<Lead>(); //List of Leads which will be auto converted.
    // if process = false ; the trigger functionality is not required for the 
    // incoming Leads
    boolean process = false; 

        for(Lead leadObj : Trigger.new){
        system.debug('OwnerId^^^' + leadObj.OwnerId);
        system.debug('AccOwnerId^^^' + leadObj.OWNER_ID__C);
        system.debug('ContOwnerId^^^' + leadObj.OWNER_ID_TO_CONTACT__C);
        system.debug('OpprtOwnerId^^^' + leadObj.OWNER_ID_TO_OPPORTUNITY__C);

                process = true;
       Lead_Triggers ClassObj = new Lead_Triggers();  
    catch(Exception e){
        Exception__c exp = ExceptionHandler.logException(new Exception__c(Class_Name__c = 'AutoConvertLead', 
                                                                          Method_Name__c = 'Database.LeadConvertResult', 
                                                                          Message__c = e.getMessage())); 

Getting below error message when converting lead into opportunity.

enter image description here Thanks.

  • Can you post corresponding apex class also?
    – Reshma
    Mar 23, 2017 at 6:54
  • 1
    @ranirube Post the code of this leadconvert Mar 23, 2017 at 6:54
  • 1
    Basically it is saying you are not populating those fields when u should be
    – Eric
    Mar 23, 2017 at 7:13
  • While converting the testLead it should populate the testLead.Category__c='XYZ'; and testLead.SubCategory__c='PQR';
    – RCS
    Mar 23, 2017 at 7:31
  • @RCS- But these two fields are not there in Lead object.
    – rani rube
    Mar 23, 2017 at 7:59

1 Answer 1


I think there is one more way to make it working. Go to Customize --> Lead --> Lead Settings. Unchecked the checkbox Require Validation for Converted Leads. This will won't run any validations on Opportunity and your lead can be converted into opportunity without any errors.

Refer below snapshot:

enter image description here

  • @ranirube It was a learning for me too :) Mar 23, 2017 at 10:44

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.