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
Dheeraj shokeenDheeraj shokeen 

Test Calss Code Coverage issue

Test Class code Coverage Working fine but i manot able to achieve the 75% code coverage
so issue is My code have multiple of condition so how to acheieve it.

@isTest
public class LeadReceiver_Test {
    
 @isTest static void Unit_Phone()
  {
      List<Lead>listl = new list<Lead>();
      Profile p = [SELECT Id FROM Profile WHERE Name='System Administrator']; 
            User usr = new User(Alias = 'standt', Email='Dheeraj@gmail.com', 
                        EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US', 
                        LocaleSidKey='en_US', ProfileId = p.Id, 
                        TimeZoneSidKey='America/Los_Angeles', UserName='Dheeraj1@testorg.com');
            insert usr ;
     Account acc = new account();
      acc.name='XYZ1';
      acc.phone='123456';
      Insert acc;
      contact ac = new contact();
      ac.firstname='test';
      ac.LastName='Sharma';
      ac.Email='d@example.com';
      ac.AccountId=acc.Id;
      ac.MailingStreet='Test';
      ac.MailingCity='test';
      ac.MailingCountry='United States';
      ac.MailingPostalCode='12345';
      ac.MailingState='Florida';
      insert ac;
      
      RestRequest request = new RestRequest();
      request.requestURI=  URL.getSalesforceBaseUrl().toExternalForm()+'/Services/Apexrest/PostLead/';
      request.httpmethod='POST';
      request.addheader('Content_Type','Application/json');
      request.addheader('Accept','Application/json');
      Lead lr = new lead(firstname='test record1',Lastname='test1',Title='Mr.',Email='dd8@example.com',Company='test1',Street='test1',City='test',State='ohio',phone='122333',Description='test Class1',
                        PostalCode='12345',Country='United states',Language__c='English',Status='New',NumberOfEmployees=12,SIC_Code__c='1234',LeadSource='Website',Website='www.test1.com',OwnerId=usr.Id,
                        Lead_Num__c='12356',Campaign_Name__c='Website1',Campaign_Initiative__c='Website1',Project_Number__c='Website1',Sales_Representative_Name__c='Website1',
                        Persona__c='Website');
     Insert lr;
      String bodyStr='[{"Sendtoemail":"'+usr.Email+'","LeadStatus":"New","FirstName":"test1","LastName":"Sharma1","Title":"MR","Company":"XYZ","Phone":"123456","Email":"dd@example.com","Street":"Test","City":"test","State":"California","Country":"United States","ZipCode":"12345","Website":"www.gmail.com","Description":"test class","SIC":"123","noOfEmployees":"122","LeadSource1":"Website","LUID":"1234","LeadSource2":"Website","LeadSource3":"Website","LeadSource4":"Website","RepName":"test rep","Persona":"Test is test","SalesforceID":"'+lr.id+'"}]';
      string requestbody = JSON.serialize(listl);
      request.requestbody=Blob.valueof(bodyStr);
      RestContext.request = request;
      LeadReceiver.dopost();
      //List<LeadReceiver.LeadRecord>listrec = new List<LeadReceiver.LeadRecord>(listl); 
  }
 
SwethaSwetha (Salesforce Developers) 
HI Dheeraj,
The code provided in question does not highlight the uncovered lines. The below articles give a good insight into how coverage can be improved
 
https://salesforce.stackexchange.com/questions/244794/how-do-i-increase-my-code-coverage-or-why-cant-i-cover-these-lines 

Code Coverage Best Practices
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_code_coverage_best_pract.htm
 
Checking Code Coverage
https://help.salesforce.com/articleView?id=code_dev_console_tests_coverage.htm&type=5
 
Deployment related code coverage issues
https://help.salesforce.com/articleView?id=000335222&type=1&mode=1
 
https://salesforce.stackexchange.com/questions/148894/help-required-to-get-full-code-covered-in-test-class

If this information helps, please mark the answer as best. Thank you