+ Start a Discussion
Anshul BagdiyaAnshul Bagdiya 

How do I increase code coverage for the following apex class? Currently, its at 74%.

Public class AutoConvertLeads
    public static void LeadAssign(List<Id> LeadIds)
            Database.LeadConvert Leadconvert = new Database.LeadConvert();
            LeadStatus Leads= [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
            Database.LeadConvertResult Leadconverts = Database.convertLead(Leadconvert);
Ruwantha  LankathilakaRuwantha Lankathilaka
Try following code it should give you 100% coverage 
@IsTest(SeeAllData = true)
public with sharing class ApexTest_AutoConvertLeads {

    static testMethod void testLeads(){

        Map<Id,Lead> idLeadMap = new Map<Id, Lead>([SELECT Id FROM Lead LIMIT 1000]);

        AutoConvertLeads.LeadAssign(new List<Id>(idLeadMap.keySet()));

If this helps you please mark it as the best answer so it could help the community in many ways.
Amit Chaudhary 8Amit Chaudhary 8
I will recommend you to start using trailhead to learn about test classes
1) https://trailhead.salesforce.com/modules/apex_testing

Also please check below post
1) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_qs_test.htm
2) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_example.htm

Please check below for sample test classes
1) http://amitsalesforce.blogspot.com/2015/06/best-practice-for-test-classes-sample.html

Please try below test class
public with sharing class AutoConvertLeadsTest {

    static testMethod void testLeads(){

        Lead newLead = new Lead() ;
        newLead.FirstName = 'Cole';
        newLead.LastName = 'Swain';
        newLead.Company = 'BlueWave';
        newLead.Status = 'contacted';	
		insert newLead;
		List<Id> LeadIds = new List<Id>();

NOTE:- Try to avoid to use SeeAllData = true

Let us know if this will help you