• Marina Kostopoulou
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
I don't have previous experience with Apex Code. I created an apex class that converts the Lead to Account and I write a simple test. With the current status my code coverage is 44% and I need at least 75% in order to deploy it in production. Can someone help me write that ?


Apex Class
Public class AutoConvertLeads
{
    @InvocableMethod
    public static void LeadAssign(List<Id> LeadIds)
    {
        
        List<Database.LeadConvert> MassLeadconvert = new List<Database.LeadConvert>();
        for(id currentlead: LeadIds){
                Database.LeadConvert Leadconvert = new Database.LeadConvert();
                Leadconvert.setLeadId(currentlead);                
                Leadconvert.setConvertedStatus('Qualified');
                MassLeadconvert.add(Leadconvert);
        }
        
        
        if (!MassLeadconvert.isEmpty()) {
            List<Database.LeadConvertResult> lcr = Database.convertLead(MassLeadconvert);
        }
    }
}
Test Class
@isTest
private class AutoConvertLeads_Test{
  static testMethod void test_LeadAssign_UseCase1(){
    AutoConvertLeads obj01 = new AutoConvertLeads();
    AutoConvertLeads.LeadAssign(new List<Id>());
  }

}


 
I don't have previous experience with Apex Code. I created an apex class that converts the Lead to Account and I write a simple test. With the current status my code coverage is 44% and I need at least 75% in order to deploy it in production. Can someone help me write that ?


Apex Class
Public class AutoConvertLeads
{
    @InvocableMethod
    public static void LeadAssign(List<Id> LeadIds)
    {
        
        List<Database.LeadConvert> MassLeadconvert = new List<Database.LeadConvert>();
        for(id currentlead: LeadIds){
                Database.LeadConvert Leadconvert = new Database.LeadConvert();
                Leadconvert.setLeadId(currentlead);                
                Leadconvert.setConvertedStatus('Qualified');
                MassLeadconvert.add(Leadconvert);
        }
        
        
        if (!MassLeadconvert.isEmpty()) {
            List<Database.LeadConvertResult> lcr = Database.convertLead(MassLeadconvert);
        }
    }
}
Test Class
@isTest
private class AutoConvertLeads_Test{
  static testMethod void test_LeadAssign_UseCase1(){
    AutoConvertLeads obj01 = new AutoConvertLeads();
    AutoConvertLeads.LeadAssign(new List<Id>());
  }

}