You need to sign in to do that
Don't have an account?
Steve 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...
Please help save my sanity -- I don't understand why I'm getting 0% coverage of the trigger.
Thanks,
Here's my test code....
Here's the trigger...
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)
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); } }
If you are deploying together then you are getting any 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).
- Executes all before triggers.
- 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.
- 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.
- Saves the record to the database, but doesn't commit yet.
- Executes all after triggers
Do you have the same required fields for the accounts and opportunities in production and in your sandboxes?