+ Start a Discussion
karthik Jonnalagaddakarthik Jonnalagadda 

Code coverage issue

Hello All,

I Have CreateNewLead class and CreateNewLeadTest classes. I run the test class it showing test is passes but Code Coverage 0% (0/20). What was the reson Please help out . code bellow.
global class CreateNewLead


global static void NewLead()

 RestRequest req = RestContext.request;

        String bdy = req.requestBody.toString();
         new_member_registration member = (new_member_registration)JSON.Deserialize(bdy,new_member_registration.class);
          List<Lead> NoLeads=[Select ID from Lead where Offerboard_Member_ID__c=: member.memberId];
          Lead l = New Lead();
            if(String.isNotBlank(member.firstName) && String.isNotEmpty(member.firstName))
               l.FirstName = member.firstName;
                if(String.isNotBlank(member.lastName) && String.isNotEmpty(member.lastName))
                l.LastName = member.lastName;
                 if(String.isNotBlank(member.memberId) && String.isNotEmpty(member.memberId))
                l.Offerboard_Member_ID__c = member.memberId;
                 if(String.isNotBlank(member.companyName) && String.isNotEmpty(member.companyName))
                l.Company = member.companyName;
                 if(String.isNotBlank(member.memberType) && String.isNotEmpty(member.memberType))
                l.Member_Type__c = member.memberType;
                 if(String.isNotBlank(member.email) && String.isNotEmpty(member.email))
                l.Email = member.email;
                if(String.isNotBlank(member.phone) && String.isNotEmpty(member.phone))
                l.Phone = member.phone;                 
                l.Date_Member_Joined__c = member.datejoined == null ? null : member.datejoined.date();
                Database.SaveResult sr;          
                sr = database.insert(l,false);
                sr = database.update(l,false);          
catch(Exception ex)
system.debug('ERROR: '+ex.getMessage());


  public class new_member_registration{
    public String memberId;
    public String memberType;
    public String firstName;
    public String lastName;
    public String companyName;
    public String email;
    public DateTime datejoined;
    public String phone;


Test Class  code
Private class CreateNewLeadTest {
  testmethod Private static void TestCreateNewLead()
        Lead ObjLead=new Lead(FirstName ='karthik-test',LastName ='reddy-Test',Offerboard_Member_ID__c ='1234567',Company ='Test-Company',Member_Type__c ='Investor',Email ='karthik@test.com',Phone ='9032793424',Date_Member_Joined__c=Date.today());
        Insert ObjLead;
        Lead L=[select Offerboard_Member_ID__c from lead where id=:ObjLead.id];
        system.assertEquals(L.Id, ObjLead.Id);

Andy BoettcherAndy Boettcher
Is there a trigger in play here?  You're just doing a basic DML in your test class - your main class is a REST service.  To test a REST service, you need to assemble a RestRequest and pass it to the service.