You need to sign in to do that
Don't have an account?
Test Class not updating opp?
I'm writing a test class for a trigger that runs on after insert or after update on Opps. My after insert test is working fine but I can't seem to get the update test to work.
// Create the new Opportunity record Account a = new Account(~sets fields~); Opportunity opp = new Opportunity(CurrencyIsoCode = 'EUR', License_Amount__c = double.valueOf('1000.00') ~sets other required fields~); insert opp; test.startTest(); opp.License_Amount__c = double.valueOf('2000.00'); update opp; test.stopTest(); //query the updated opp Opportunity oppRecordUpdated = [SELECT Amount_USD__c, Amount FROM Opportunity WHERE ID = :opp.ID]; // If the trigger works, then the opp's Amount_USD__c field should now be 2000 EUR converted to USD System.assertEquals(Math.roundtolong(oppRecordUpdated.Amount_USD__c), Math.roundtolong(oppRecordUpdated.Amount / EUR.ConversionRate)); } }
what's happening is Amount USD is not getting updated - the number returned is based on what happened on the insert, not on the update. When I check my code coverage on the trigger, it shows the update trigger as NOT having coverage. How do I ensure that update trigger is run? Thought I had it with the starttest statement but apparently not.
Hope this helps !!!!!!!
Sent from my iPhone
All Answers
I believe update does not pass your if:
it seems that condition is true only if "old" or "new" opportunity is Closed. In your test class you don't set the opportunity to close before update statement.....
Hope this helps !!!!!!!
Sent from my iPhone
Thanks so much, Sandeep! If you're at dreamforce, I'll buy you a beer :)
Sent from my iPhone