You need to sign in to do that
Don't have an account?
Jean-Se Dorais
0% Code Coverage!?!
Hello all,
I've got a 'FundingAwardTrigger' on the FundingAward object (part of the Grantmaking package). When I run the test in Sandbox, I get 100% coverage.
When I validate the Inbound Change Set in Prod, I get the following error:
Code Coverage Failure
The following triggers have 0% code coverage. Each trigger must have at least 1% code coverage.
FundingAwardTrigger
Here's my test class:
Any tips appreciated!
I've got a 'FundingAwardTrigger' on the FundingAward object (part of the Grantmaking package). When I run the test in Sandbox, I get 100% coverage.
When I validate the Inbound Change Set in Prod, I get the following error:
Code Coverage Failure
The following triggers have 0% code coverage. Each trigger must have at least 1% code coverage.
FundingAwardTrigger
Here's my test class:
@isTest private class FundingAwardTriggerTest { @isTest static void testTriggerOnInsert() { // Create a test record for the insert operation FundingAward testAwardInsert = new FundingAward(Name = 'Test Insert', Amount = 100); // Start the test context Test.startTest(); // Perform the insert operation insert testAwardInsert; // Stop the test context Test.stopTest(); // Retrieve the inserted record and assert the result testAwardInsert = [SELECT Currency_Text__c FROM FundingAward WHERE Id = :testAwardInsert.Id]; System.assertEquals('One Hundred', testAwardInsert.Currency_Text__c, 'Trigger did not work as expected on insert'); } @isTest static void testTriggerOnUpdate() { // Create and insert a record for the update operation FundingAward testAwardUpdate = new FundingAward(Name = 'Test Update', Amount = 100); insert testAwardUpdate; // Start the test context Test.startTest(); // Perform the update operation testAwardUpdate.Amount = 200; update testAwardUpdate; // Stop the test context Test.stopTest(); // Retrieve the updated record and assert the result testAwardUpdate = [SELECT Currency_Text__c FROM FundingAward WHERE Id = :testAwardUpdate.Id]; System.assertEquals('Two Hundred', testAwardUpdate.Currency_Text__c, 'Trigger did not work as expected on update'); } @isTest static void testBulkOperation() { // Create multiple records for testing bulk operation List<FundingAward> awards = new List<FundingAward>(); for (Integer i = 1; i <= 10; i++) { awards.add(new FundingAward(Name = 'Bulk Test Award ' + i, Amount = i * 100)); } // Start the test context Test.startTest(); // Perform bulk insert insert awards; // Update the records for bulk update test for (Integer i = 0; i < awards.size(); i++) { awards[i].Amount += 1000; } // Perform bulk update update awards; // Stop the test context Test.stopTest(); // Optional: Add assertions here to validate the trigger's behavior on bulk operations } }Why would my test class show 100% in sandbox but 0% in prod?
Any tips appreciated!
All Answers
Hope this helps!
Check similar references below.
https://developer.salesforce.com/forums/?id=9062I000000DIXqQAO
https://trailhead.salesforce.com/trailblazer-community/feed/0D54S00000A8JLJSA3
Please mark it as Best Answer if the above information was helpful.
Thanks.
Important Update - last chance
Heads up — this is your last chance to get your Trailblazer account set up and connected to your forums discussions on this site.
Please take these steps before November 30, 2023, 11:59 p.m. PT to ensure your contributions follow you to the Trailblazer Community:
- If you’re not already a member of the Trailblazer Community, sign up for a Trailblazer account using the same login email address associated with your Developer Discussion Forums account. This is crucial.
- If you already have a Trailblazer account, and it’s using a different email address from your Developer Discussion Forums account, we recommend that you log in to the Trailblazer Community and connect your forums email address to your Trailblazer account.
Find more info & supportWe know that moving platforms can be a hassle, so we created a special forums users group, the Migration Support Hub, in the Trailblazer Community where you can find other forums users and get training videos, the latest information, and assistance.
We want to thank you for all of your time, energy, and contributions made here in the Salesforce Discussion Forums.
We’ll see you in the Trailblazer Community!
Sincerely,
The Forums Support Team