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
Steve BerleySteve Berley 

trigger has 42% coverage in sandbox but 0% when deploying

This is driving me nuts...

My trigger has 42% coverage in my sandbox but it won't deploy saying that the coverage is 0% (code below).  The test method both inserts and updates an opportunity. I'm lost as to why the trigger never fires.

Things I've tried so far...
  • I tried a creating new trigger and deactivating the old one. 
  • The trigger's system version was 18 - I updated it to 40.
  • I tried implementing the changes in a brand new sandbox.
  • I've given it a rest and waited 12 hours (read that trying again gets it working)
All to no avail

Please help save my sanity -- I don't understand why I'm getting 0% coverage of the trigger.

Thanks,

Here's my test code....
@isTest
private class paymentManager_test {

    @isTest static void test_addingPayments() {
        id acctRT = lpTools.getRecordTypeID('Account', 'Business');
        id oppRT = lpTools.getRecordTypeID('Opportunity', 'Donation');
        account a = new account(name = 'test', recordtypeid=acctRT);
        insert a;
        opportunity o = new opportunity(name='blah', accountid=a.id, closedate=date.today(), stagename='Pledged', amount=47, recordtypeid = oppRT);
        insert o;
        o.stagename = 'Posted';
        update o;
    }
}

Here's the trigger...
trigger opportunityTrigger on Opportunity (before insert, before update, before delete, after insert, after update, after delete, after undelete) {

    // Add payments to newly closed opps
    if (trigger.isAfter){
        list<Opportunity> inNeed = new list<Opportunity>();
        if (trigger.isInsert) {
            for (Opportunity is : trigger.new) { 
                if (is.stagename == 'Posted' && is.amount > 0) inNeed.add(is);
            }
        }
        else if (trigger.isUpdate){
            for (Opportunity is : trigger.new) {
                Opportunity was = trigger.oldmap.get(is.id);
                if (is.stagename == 'Posted' && is.amount > 0 && is.Num_Payments__c == 0 && (was.stagename != 'Posted' || was.amount == null || was.amount == 0)) inNeed.add(is);
            }
        }
        paymentManager.addPayments(inNeed);
    }
}


 
Amit Chaudhary 8Amit Chaudhary 8
Are you deploying test class with Trigger together ?
If you are deploying together then you are getting any error ?
Alain CabonAlain Cabon
You should see an error.
https://developer.salesforce.com/forums/?id=906F00000008zEDIAY

id acctRT = lpTools.getRecordTypeID('Account', 'Business');
id oppRT = lpTools.getRecordTypeID('Opportunity', 'Donation');

The test class failed during the insert of the account or the opportunity so there is not "after insert" at all (logically).
  1. Executes all before triggers.
  2. Runs most system validation steps again, such as verifying that all required fields have a non-null value, and runs any user-defined validation rules. The only system validation that Salesforce doesn't run a second time (when the request comes from a standard UI edit page) is the enforcement of layout-specific rules.
  3. Executes duplicate rules. If the duplicate rule identifies the record as a duplicate and uses the block action, the record is not saved and no further steps, such as after triggers and workflow rules, are taken.
  4. Saves the record to the database, but doesn't commit yet.
  5. Executes all after triggers
Do you have the same required fields for the accounts and opportunities in production and in your sandboxes?