function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Mohammad Alazzouni 16Mohammad Alazzouni 16 

Can't get my code coverage over 17%. Help!

I have been going crazy trying to find out why my code coverage cannot go above 17%. 

I am trying to deply an Apex Class. I have never done tests before so I am not sure if my tests are appropriate.

The idea is to have a Process Builder workflow trigger an immediate action that will reference an Apex class to convert a Lead to a Contact 

This is my code:
 
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);
        }
    }
}
When I deply or run a test. I can never seem to get my code coverage above 17%. 

See below fo the error message. Not too sure what to do.

User-added image
 
arpit vijayvergiyaarpit vijayvergiya
Hello,
You should, run your test class in the sandbox before deploying it to production. If it covers 75% in the sandbox and fails in production then kindly describe the process you are running test class.
Thanks
Waqar Hussain SFWaqar Hussain SF
Hi,

The Offer_Owner__c field is required but in your test data you are not setting value to this field. Make proper data with all required fields and then try again.

THanks