deploy issue: run test pass, but when i deploy to production, it still display Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required, can anyone tell me what i miss here ?

Apex Trigger:

failed to deploy: message: "Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required"

trigger CreateNewTask10 on Lead (after insert) {

List<Task> lNewTasks = new List<Task>();
for (Integer i = 0; i < Trigger.new.size(); i++) {

         if (Trigger.new[i].Comments__c !=null) {
            lNewTasks.add(new Task(
                ActivityDate = Date.today().addDays(7),
                Status = 'Not Started',
                Subject='trigger add New Comment',
                description = Trigger.new[i].Comments__c

insert lNewTasks;

Apex class - test and pass

 public class UnitTests_CreateNewTask10 {

  static testMethod void CreateNewTask10() {

  //Set up user
  User u1 = [SELECT Id FROM User WHERE Alias='auser'];


  //Run As U1

  Lead l = new Lead(
       FirstName='Test firstName',
       LastName = 'Test LastName', 
       Comments__c = '18888 test comments'

  insert l;
  System.debug('Created and inserted lead');

  List<Task> tasks = new List<Task>();

  tasks.add(new Task(
     ActivityDate = Date.today().addDays(7),
     WhoId = l.Id,
     Status = 'Not Started',
     Subject='trigger add New Comment',
     Description = l.Comments__c

  insert tasks;
  System.debug('Created and inserted task');

  Task Ttest = [SELECT Whoid, Description FROM Task WHERE Whoid=:l.Id Limit 1];

  system.assertEquals('18888 test comments', Ttest.Description);


    } //end RunAs(u1)


  • What happens when you run the test(from the UI not Eclipse) and then go back to the trigger, do you see any percentage or is still at 0%?
    – PepeFloyd
    Commented Jul 25, 2013 at 21:17
  • Just reading through your code here and noticed you are manually creating the task and doing your asserts against that. You shouldn't be manually creating the task as the trigger does that for you. If you remove everything from the task list instantiation to the system.debug('Created and inserted task'); inclusive that should fix it.
    Commented Jul 25, 2013 at 23:35

3 Answers 3


Is there a reason you are running as another user. If there is no real reason it should be removed.

I removed that and then I recreated your code in my dev org and was able to deploy to another org without issues.

  • Thanks for the reply, i am OK to upload from sandbox to production as well by outbound change set. but it failed to validate under production, and that is why i can't deploy to production. Also i think i did test with/without runAs user or use my alias - admin privilege, it failed too. and i am not sure if you did actually test the validate under your production and pass ? or could you please post the unit test code for me to test here? thanks a lot.
    – webon100
    Commented Jul 25, 2013 at 20:55
  • Ahh. sorry misunderstood. I have run into this before and for some reason (could be coincidence) was able to get around it if I deployed the test class to production first. Then once it was there did a second deployment with the trigger itself. Commented Jul 25, 2013 at 21:07
  • Hi Dunc44, it works now. the issue is test class need to deploy as well. Thanks a lot.
    – webon100
    Commented Jul 25, 2013 at 22:10
  • Great, glad it worked. Commented Jul 25, 2013 at 22:12
  • @webon100 Can you 'accept' this answer, please?
    – metadaddy
    Commented Jul 26, 2013 at 17:12

All triggers must have some amount of Test code coverage to get deployed .Your Trigger has 0% coverage as the error says .One reason i see here is you are running as some other user and he may not be system administrator profile.All triggers execute in admin context.Hence run your test class as System Admin

  • sure, my user under sys admin, and i did create APEX test class without runAs, and it failed, and someone suggest to use runAs, and unfortunately, it still the same ... also is that the reason the class should be cover under the package ? or please advise what should i test then? thanks.
    – webon100
    Commented Jul 25, 2013 at 21:00
  • it shows "Your overall code coverage is currently 82%. To deploy code to production, you must have at least 75%." under production, and i had runAs removed and my login is under admin privilege, and deploy under production fail again. please advise.
    – webon100
    Commented Jul 25, 2013 at 21:26

I had similar problem once. Deploy to test was fine but to production failed as described. I was deploying a small subset of all the classes but it was a complete set meaning none of the classes in the deploy set needed any class outside of the set. The problem is production deployment triggers a full test of all classes. Only way I could solve the issue is to deploy all classes in the system.

Your can read more about my attempts here: http://sforcehacks.blogspot.ca/2014/01/debug-statements-stopped-working-on.html

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .