+ Start a Discussion
Nagendra SinghNagendra Singh 

I am converting a lead into Account it is throughing an error:System.DmlException: ConvertLead failed. UNKNOWN_EXCEPTION,Insert failed.REQUIRED_FIELD_MISSING, Required fields are missing: : [CloseDate]

Anoop yadavAnoop yadav
Hi Nagendra,

Are you using any apex code to convert the Lead?.
If yes, This error belongs to opportunity close date.
Nagendra SinghNagendra Singh
Hi Anoop
                Yes i am using Apex code to convert lead.code is here below pls suggest solution.
     I have a trigger which convert a lead if status is qualified ,into account 
    Excetion is at Line 'Database.LeadConvertResult lcResults = Database.convertLead(leadsToConvert);'

static testMethod void testConvertLead() {
   
    // Variables to use in testing
       
        MBA_Staging_Account__c objMBAAcct;
        MBA_Staging_Subscription__c objMBASub;
        MBA_Staging_Contact__c objMBAContact;
      
       
      
         TestDataGenerator td = new TestDataGenerator();
        // Initialize the Custom Setting Map   
        td.getStagingToTableMappingSettings();
       
     
       
        // Create Staging Account records as not Paid and grab one of them
       
        objMBAAcct = new  MBA_Staging_Account__c();
        objMBAAcct.MBAAccountID__c='test1opp7014';
        objMBAAcct.CompanyName__c='company7014';
        insert objMBAAcct;
       
       
        // Create Staging Contact records as not Paid
       
        objMBAContact=new MBA_Staging_Contact__c();
        objMBAContact.MBAAccountID__c=objMBAAcct.MBAAccountID__c;
        objMBAContact.Email__c='test1opp7014@gmail.com';
        objMBAContact.MBAClientID__c='clienttest1opp7014';
        insert objMBAContact;
       
       
       
               
        // Create Staging Subscription records as paid
       
        objMBASub = new MBA_Staging_Subscription__c();
        objMBASub.MBASubscriptionID__c='sub1testopp77014';
        objMBASub.MBAAccountID__c = objMBAAcct.MBAAccountID__c;
        objMBASub.isTrial__c=true;
        objMBASub.SubscriptionType__c ='Store';
        insert objMBASub;
       
        //creating a lead for converting it
       
        Lead objlead=new Lead();
        objlead.LastName='test1lead2014';
        objlead.Company='testcompany';
  objlead.Stage__c ='New';
        objlead.MBAAccountID__c=objMBAAcct.MBAAccountID__c;     
       
        Database.SaveResult saveResults = Database.Insert(objlead);

      // Create a LeadConvert instance to be used
     
     
      Database.LeadConvert leadsToConvert = new Database.LeadConvert();
        
           
            leadsToConvert.setConvertedStatus('Qualified');
            leadsToConvert.setLeadId(saveResults.getId());
         
       
       
      // Convert the leads
      Database.LeadConvertResult lcResults = Database.convertLead(leadsToConvert);
     
        // Start Test
        test.startTest();
       
       
       
       
       
       
       
        test.stopTest();
   
   
    }
Anoop yadavAnoop yadav
Hi Nagendra,

Is your Trigger working fine?

For Test method,
You should insert a lead, After that change the status to "Qualified" and then update that lead.

Lead l = new Lead(Name = 'Test Lead', Company = 'Test Company', Status = 'New');
insert l;
l.Status = 'Qualified';
update l;


Nagendra SinghNagendra Singh
Hi Anoop
              Yes my trigger is working fine .no problem with it.
   
            i put your code but problem is still there at same line "Database.LeadConvertResult lcResults = Database.convertLead(leadsToConvert);" 
       
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: [CloseDate]: [CloseDate]


Anoop yadavAnoop yadav
Do not use the below part of your code.

Database.SaveResult saveResults = Database.Insert(objlead);

      // Create a LeadConvert instance to be used
    
    
      Database.LeadConvert leadsToConvert = new Database.LeadConvert();
       
          
            leadsToConvert.setConvertedStatus('Qualified');
            leadsToConvert.setLeadId(saveResults.getId());
        
      
      
      // Convert the leads
      Database.LeadConvertResult lcResults = Database.convertLead(leadsToConvert);
   


When you will update update lead , by default it will call the above method.

Nagendra SinghNagendra Singh
Hi Anoop,
                You Are right but to fire my trigger i have to insert  a lead then convert it.
Anoop yadavAnoop yadav
Where you have written the code to convert the lead and what is your triggring condition?
is that on Lead?
Nagendra SinghNagendra Singh
Hi Anoop,
              My problem solved .Thanks for help .Thanks A Lot.