• PrashantK
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies

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.

Hi All,

I have created Custom Field in Contact Object (Name: RegistrationAccount), but when I try to access it my Apex code its giving an error.

Code:

Contact c = new Contact(    
            AccountId=a.Id,
            FirstName = firstName,
            LastName = lastName,
            Account = a,
            Department = department,
            RegistrationAccount='UVA',   // My Custom Field
            Email = email,
            Phone=phone,
            Title = title,
            MailingStreet = streetAddress,
            MailingCity = cityAddress,
            MailingState = stateAddress,
            MailingPostalCode = postalCodeAddress,
            MailingCountry = countryAddress);

insert c;

 

Error: Compile Error: Invalid field RegistrationAccount for SObject Contact at line 45 column 33

Custom Field API Name :Registration Account_c

Hi All,

I have created Custom Field in Contact Object (Name: RegistrationAccount), but when I try to access it my Apex code its giving an error.

Code:

Contact c = new Contact(    
            AccountId=a.Id,
            FirstName = firstName,
            LastName = lastName,
            Account = a,
            Department = department,
            RegistrationAccount='UVA',   // My Custom Field
            Email = email,
            Phone=phone,
            Title = title,
            MailingStreet = streetAddress,
            MailingCity = cityAddress,
            MailingState = stateAddress,
            MailingPostalCode = postalCodeAddress,
            MailingCountry = countryAddress);

insert c;

 

Error: Compile Error: Invalid field RegistrationAccount for SObject Contact at line 45 column 33

Custom Field API Name :Registration Account_c

 

Hello,
I am trying to write a APEX Webservice that will be called from .NET. Before trying to use it at NET i wanted to test the WS Class I wrote in the APEX using a test class. Does anyone have examples of any test classes to test the APEX Web services?
Appreciate your response.