• Lauren Hanna 24
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
I snatched this code off the internet to use with Process Builder to auto convert leads meeting a certain criteria. The class works fine but the I can't seem to get any test coverage. I included the class and test class below. Can anyone tell me what I am doing wrong? 
public class AutoConvertLeads
{
    @InvocableMethod
    public static void LeadAssign(List<Id> LeadIds)
    {
        LeadStatus CLeadStatus= [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true Limit 1];
        List<Database.LeadConvert> MassLeadconvert = new List<Database.LeadConvert>();
        for(id currentlead: LeadIds){
                Database.LeadConvert Leadconvert = new Database.LeadConvert();
                Leadconvert.setLeadId(currentlead);                
                Leadconvert.setConvertedStatus(CLeadStatus.MasterLabel);
                Leadconvert.setDoNotCreateOpportunity(TRUE); //Remove this line if you want to create an opportunity from Lead Conversion 
                MassLeadconvert.add(Leadconvert);
        }
        
        if (!MassLeadconvert.isEmpty()) {
            List<Database.LeadConvertResult> lcr = Database.convertLead(MassLeadconvert);
        }
    }
}







​​​​​​​
@IsTest (SeeAllData=true) private class AutoConvertLead_Test{

    /* This is a basic test which simulates the primary positive case for the 
       Conversion method of a Lead. */

public static testMethod void myUnitTest() {

// create a Lead
Lead lead=new Lead(LastName='TestDoe',FirstName='TestJane',Company='TestUnknown',Status='Warm Prospect',Addy_Account_id__c='1234566');

insert lead;


Database.LeadConvert lc = new database.LeadConvert();
lc.setLeadId(lead.id);
lc.setDoNotCreateOpportunity(true);
lc.setConvertedStatus('User');

Database.LeadConvertResult lcr = Database.convertLead(lc);
System.assert(lcr.isSuccess());
}}