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
Ryan GreeneRyan Greene 

100% code coverage in development but 0% in change set

Hello All,
I wrote a simple Trigger to not allow deletion of a specific record. Also, I wrote a Test Class with 100% code coverage in dev. When attempting change set I am receiving a Code Coverage Failure, with 0% code coverage. What is happening? I have tried the Change Set as both Default, and only run the Test related to my Trigger. I am deploying both in the same Change Set. All suggestions appreciated!
Thanks, Ryan
Trigger:
trigger callapplyTrigger on Lead (before update, before insert,before delete){
    if(Trigger.isDelete){
        for (Lead l : [SELECT Id,Email FROM Lead WHERE Email = 'testingtrigger1@test.com' AND Id IN :Trigger.old]){
            Trigger.oldMap.get(l.Id).addError(
                'Cannot delete this Lead.');
        }
    }
}
Test Class:
@isTest
public class Test_callApply {
    @isTest static void TestDelete(){
        Lead lead = new Lead(Segment__c='Small Group',Email='testingtrigger1@test.com',
                             FirstName='testRyan',LastName='testGreene',Status='New',
                          Company='testCompany',City='Orlando',State='FL',LeadSource='Event');
        insert lead;
        
        Test.startTest();
        Database.DeleteResult result = Database.delete(lead,false);
        Test.stopTest();

        System.assert(!result.isSuccess());
        System.assert(result.getErrors().size() > 0);
        System.assertEquals('Cannot delete this Lead.',result.getErrors()[0].getMessage());
    }
}

 
GauravGargGauravGarg

Hi Ryan,

Can you try removing system.assert() and then validate the changeset. 


THanks,

Gaurav
 

Mounica M 10Mounica M 10

Hello,

I kind off faced the same problem.  

you should not run it in default try the Run Specified Tests and give the name of your test class in the the box.

this solved my issue

 

Ryan GreeneRyan Greene
Hey guys, I did Run Specified Tests of just the Test for my Trigger, which was in the same Change Set. The Change set only contains the Trigger and Test.
I also removed all three System.assert() and I still get Code Coverage Error, 0% code coverage.
I've deployed a lot of code and a lot Test code in the past and have never run into this issue! 
GauravGargGauravGarg
Hi Ryan,

I ran the same problem sometime back and found there was some internal error from salesforce side. I tried running the specific test after 24 hours and the same changeset worked for me. 

 
v varaprasadv varaprasad
Hi Ryan,

In your target org if you have following record [SELECT Id, Email FROM Lead WHERE Email = 'testingtrigger1@test.com' AND Id IN :Trigger.old

Means email like @testingtrigger1@test.com.
If you don't have that email you trigger will not run I think.


Hope this helps you!

Thanks
Varaprasad
@For Support: varaprasad4sfdc@gmail.com