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
PrashantKPrashantK 

Apex web service deployment error.

Hi All,

 

I am new in deploying classes on production, I am getting error "Average test coverage across all Apex Classes and Triggers is 54%, at least 75% test coverage is required." at the time of its deployement in production but when i test it on sandbox its shows code coverage 100%. Hope you will help me for this.

My Class:

global class CustomerContact
{
   webService static void Event(String Id,Integer yyyy,Integer mm,Integer dd,String sub,String description)
    {   
    Task task = new Task();   
    task.WhoId = Id;
    task.Subject = sub;
    task.priority= 'Normal';
    task.status = 'Completed';
    task.description = description;   
    task.ActivityDate=date.newInstance(yyyy,mm,dd);
    insert task;
    
    }
    
    webService static String save(String companyName,Integer numEmployees,String streetAddress,String cityAddress,
    String stateAddress,String postalCodeAddress,String countryAddress,String department,String phone,
    String firstName,String lastName,String title,String email,String university)       
    {
        String fname=firstName;
        String lname=lastName; 
        Account a = new Account(
            Name = companyName,
            NumberOfEmployees = numEmployees,
            ShippingStreet = streetAddress,
            ShippingCity = cityAddress,
            ShippingState = stateAddress,
            ShippingPostalCode = postalCodeAddress,
            ShippingCountry = countryAddress);

        insert a;
        String AccId=a.Id;        
               
        Contact c = new Contact(    
            AccountId=a.Id,
            FirstName = firstName,
            LastName = lastName,
            Account = a,
            Department = department,
            Registration_Account__c = university,
            Email = email,
            Phone = phone,
            Title = title,
            MailingStreet = streetAddress,
            MailingCity = cityAddress,
            MailingState = stateAddress,
            MailingPostalCode = postalCodeAddress,
            MailingCountry = countryAddress);

        insert c;
        
        Contact ct = [select Id from  Contact where AccountId=:AccId];
        return string.valueof(ct.Id);   
        }         
}

 

And Test Class As Fallow..

 

@isTest
private class testMyWebService
{
  
  static testMethod void testMyWebSvc()
  {      
      test.startTest();    
                             
      String Id=CustomerContact.Save('workmethods inc',1,'123 pune','Pune','Maharashtra','411046','India','Computer org','89489499','Prashant','Khadatkar','Software','prashantkhadatkar@yahoo.com','Uva University');
      Contact[] ct = [select FirstName from  Contact where FirstName='Prashant'  and LastName='Khadatkar'  and Email='prashantkhadatkar@yahoo.com'];                   
      System.assertEquals(ct.size(), 1);
      CustomerContact.Event(Id,2013,06,09,'Teaching Notes','Teaching notes reading');    
      test.stopTest();      
      

  }
}

 

Thanks in advace.

Avidev9Avidev9
there can be other classes that can bring down the Average Test Coverage.
Have a look at the production environment if all the classes has necessary test coverage
Bhawani SharmaBhawani Sharma
Can you put @seeAllData=fasle and check code coverage in production.