+ Start a Discussion
PallavPallav 

The deployment of the trigger failed on the production instance using Eclips deployment.

Hi all,

I have created a trigger whose code is  running fine  on the dev instance but when I tried to deploy in the production instace the deployment failed and gives me a error message as given below, on the third step of deployment using the Eclips deployment wizard. while validating the trigger.

Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required.

Test coverage of selected Apex Class and Trigger is 0%, at least 75% test coverage is required.

here is the code for the trigger:-
trigger trytrigger on OpportunityLineItem (after insert)
{
  if(trigger.isAfter)
   {
     if (trigger.isInsert)
      {
       for (OpportunityLineItem c :trigger.new)
        {
          Date strDate;
          Integer intDayTotal;
          Integer intMonth;
          OpportunityLineItemSchedule [] OLI = [Select Id, ScheduleDate from OpportunityLineItemSchedule where OpportunityLineItemId=:c.Id order by ScheduleDate];
          OpportunityLineItem opp = new OpportunityLineItem(Id=c.Id);
          for(OpportunityLineItemSchedule o:OLI)
           {
               strDate=o.ScheduleDate;
               Integer strMonth=strDate.month();
               Integer intDay=strDate.day();
               if(strMonth==1 || strMonth==3 || strMonth==5 || strMonth==7  || strMonth== 8 || strMonth==10 || strMonth==12)
               {
                   intDayTotal=31;
                   intDayTotal=intDayTotal-intDay;
               }
               else if(strMonth==4 || strMonth==6 || strMonth==9 || strMonth==11)
               {
                   intDayTotal=30;
                   intDayTotal=intDayTotal-intDay;
               }
               else if(strMonth==2)
               {
                   intDayTotal=28;
                   intDayTotal=intDayTotal-intDay;
               }
               strDate=strDate.addDays(intDayTotal);
               opp.Test_Field__c=strDate;
           }
           update opp;
        }
      }
   }
}

Please let me know what I am doing wrong??
Thanks in anticipation of your reponse.

thanks and regards
pallav

dkorba2k5dkorba2k5
In order to move from dev to production you must have an Apex Class built that tests out your trigger code.  That's what the message about test coverage is telling you.  Take a look in the Apex Developer's Guide and you'll see examples of building test code in order to pass the coverage requirements.
PallavPallav
Hi,

Thanks for your response. The user guide that you are talking about does not provide much instruction on how to do it... I am preety new at it and getting totally confused where to create and how to create...it would be a great favour if you can throw some light at it.

Thanks  in anticipation of your response.

regards
pallav
Rob P12Rob P12
   Try  the  Cookbook  --  Writing Unit  Tests for  Apex.  One thing I would do in your unit test is create a new record (Insert), then the next unit test step should Retrieve this record then Update it.

Now run your test to get the coverage %.
PallavPallav
Thanks a lot for your response. It really helped me to get a good understading of testing the Apex trigger. However, I am just able to make 48% of my code coverage.

here is my code for the apex class:-

public class testCodeCoverage
{
    static void me()
    {
      System.debug('test');
    }
    static testMethod void myTest()
    {
        me();
        OpportunityLineItem acccobj = new OpportunityLineItem(OpportunityId = '1111111', Description='This is a test descriptiion', Quantity=3, UnitPrice=5000, PricebookEntryId='111111');
        insert acccobj;
    }
}

To my understanding inserting a OpportunityLineItem should trigger all the lines of the trigger. Please correct me if I am wrong. Thanks in advance in anticiaption of your response. Urgent help required.

Thanks and regards
Pallav


Message Edited by Pallav on 02-05-2008 05:26 AM
JonPJonP
Since your trigger contains if statements, you must supply OpportunityLineItems that will execute each branch of the trigger's code.  If you run the tests from the Force.com IDE, the Apex Code Test Runner window will show you your coverage % and identify which lines are not coverged in each class.