You need to sign in to do that
Don't have an account?

I need help with making my following apex class 75% code coverage, right now it is at 68%. Any help is appreciated!
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>();
List<Lead> myLeads = [Select id, name, company, Matched_Account_ID__c from Lead where id IN:LeadIds];
List<String> MatchedAccount = New List<String>();
for (Lead l:myLeads){
MatchedAccount.add(l.Matched_Account_ID__c);
}
List<Account> matchAccount = [Select id, Name from account where id IN:MatchedAccount];
Integer i=0;
for(Lead currentlead: myLeads){
for (Account a:matchAccount){
if (currentlead.Matched_Account_ID__c == a.id){
Database.LeadConvert Leadconvert = new Database.LeadConvert();
Leadconvert.setLeadId(currentlead.id);
Leadconvert.setAccountId(a.id);
Leadconvert.setConvertedStatus(CLeadStatus.MasterLabel);
Leadconvert.setDoNotCreateOpportunity(TRUE); //Remove this line if you want to create an opportunity from Lead Conversion
MassLeadconvert.add(Leadconvert);
i++;
Break;
}
}
If (i==0)
{
Database.LeadConvert Leadconvert = new Database.LeadConvert();
Leadconvert.setLeadId(currentlead.id);
Leadconvert.setConvertedStatus(CLeadStatus.MasterLabel);
Leadconvert.setDoNotCreateOpportunity(TRUE); //Remove this line if you want to create an opportunity from Lead Conversion
MassLeadconvert.add(Leadconvert);
}
i=0;
}
if (!MassLeadconvert.isEmpty()) {
List<Database.LeadConvertResult> lcr = Database.convertLead(MassLeadconvert);
}
}
}
{
@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>();
List<Lead> myLeads = [Select id, name, company, Matched_Account_ID__c from Lead where id IN:LeadIds];
List<String> MatchedAccount = New List<String>();
for (Lead l:myLeads){
MatchedAccount.add(l.Matched_Account_ID__c);
}
List<Account> matchAccount = [Select id, Name from account where id IN:MatchedAccount];
Integer i=0;
for(Lead currentlead: myLeads){
for (Account a:matchAccount){
if (currentlead.Matched_Account_ID__c == a.id){
Database.LeadConvert Leadconvert = new Database.LeadConvert();
Leadconvert.setLeadId(currentlead.id);
Leadconvert.setAccountId(a.id);
Leadconvert.setConvertedStatus(CLeadStatus.MasterLabel);
Leadconvert.setDoNotCreateOpportunity(TRUE); //Remove this line if you want to create an opportunity from Lead Conversion
MassLeadconvert.add(Leadconvert);
i++;
Break;
}
}
If (i==0)
{
Database.LeadConvert Leadconvert = new Database.LeadConvert();
Leadconvert.setLeadId(currentlead.id);
Leadconvert.setConvertedStatus(CLeadStatus.MasterLabel);
Leadconvert.setDoNotCreateOpportunity(TRUE); //Remove this line if you want to create an opportunity from Lead Conversion
MassLeadconvert.add(Leadconvert);
}
i=0;
}
if (!MassLeadconvert.isEmpty()) {
List<Database.LeadConvertResult> lcr = Database.convertLead(MassLeadconvert);
}
}
}

Also want to note that i have a test class for this. Does a regular apex class need a test class?
Yes you need to cover your code in your test class.
just cover your code with all the scenario like If conditions it will inrease your code coverage.