What happens when the developer tries to deploy the trigger and two classes to production, assuming no other code exists?
A developer created this Apex trigger that calls MyClass.myStaticMsthod:
trigger myTrigger on Contact (before insert)
{ MyClass.myStaticMethod(trigger.new, trigger.oldMap); }
The developer creates a test class with a test method that calls Myclass.myStacicMethod directly, resulting in 81% overall code coverage.
What happens when the developer tries to deploy the trigger and two classes to production, assuming no other code exists?
What happens when the developer tries to deploy the trigger and two classes to production, assuming no other code exists?
A . The deployment falls because no assertions were made in the test method.
B . The deployment passes because both classes and the trigger were included in the deployment.
C . The deployment fails because the Apex trigger has no code coverage.
D . The deployment passes because the Apex code has the required =75% code coverage.
Answer: C
Explanation:
Understanding the Scenario:
Trigger Definition:
trigger myTrigger on Contact (before insert) {
MyClass.myStaticMethod(trigger.new);
}
Test Class:
The test method calls MyClass.myStaticMethod directly.
Achieves 81% overall code coverage.
The trigger is not invoked during the test.
Key Points:
Code Coverage Requirements:
Minimum 75% Coverage: To deploy Apex code to production, all Apex classes and triggers must have at least 75% overall code coverage.
Trigger Coverage Requirement: All triggers must have some code coverage, meaning they cannot
have 0% coverage.
Reference: Apex Developer Guide – Code Coverage
Deployment Guidelines
Implications for the Scenario:
Trigger Coverage:
Since the test method does not perform any operations that would fire the trigger (e.g., inserting a Contact record), the trigger myTrigger has 0% code coverage. Overall Coverage:
Even though the classes achieve 81% coverage, the trigger’s lack of coverage affects the deployment.
Deployment Outcome:
Deployment Fails: Because the trigger has 0% coverage, the deployment fails regardless of the overall coverage percentage.
Option Analysis:
Option A:
Statement: The deployment fails because no assertions were made in the test method.
While assertions are important for validating test results, the absence of assertions does not cause deployment failure due to code coverage issues.
Reference: Apex Developer Guide – Writing Effective Unit Tests
Conclusion: Incorrect.
Option B:
Statement: The deployment passes because both classes and the trigger were included in the deployment.
Inclusion of classes and triggers in the deployment does not override the requirement
for individual code coverage.
Conclusion: Incorrect.
Option C:
Statement: The deployment fails because the Apex trigger has no code coverage.
This is accurate as the trigger must have some coverage, and in this case, it has 0%.
Reference: Apex Developer Guide – Code Coverage Requirements
Conclusion: Correct.
Option D:
Statement: The deployment passes because the Apex code has the required 75% code coverage.
Although overall code coverage is above 75%, individual triggers must have some coverage (>0%). Since the trigger has 0% coverage, the deployment fails. Conclusion: Incorrect.
Best Practices:
Always Test Triggers: Ensure that your test methods perform operations that fire the triggers.
Example:
@isTest
public class MyTriggerTest {
static testMethod void testMyTrigger() {
Contact testContact = new Contact(LastName = ‘Test’);
insert testContact;
// Additional assertions can be added here
}
}
Use Assertions: While not causing deployment failure due to code coverage, assertions help validate
that the code behaves as expected.
Reference: Apex Testing Best Practices
Latest DEX-450 Dumps Valid Version with 456 Q&As
Latest And Valid Q&A | Instant Download | Once Fail, Full Refund