PD1 Testing and Debugging 3 — Questions and Answers
Question 1: Which Limits method returns the number of SOQL queries issued in the current transaction so far?
- Limits.getQueries() (Correct answer)
- Limits.getLimitQueries()
- Limits.getSoqlRows()
- Limits.getHeapSize()
Correct answer: Limits.getQueries()
Limits.getQueries() returns the number of SOQL queries already consumed in the current transaction, while getLimitQueries() returns the maximum allowed.
Question 2: A developer wants to verify that a custom exception is thrown by a method. What is the correct test pattern in Apex?
- Wrap the call in a try/catch and assert inside the catch block (Correct answer)
- Use System.expectException() before calling the method
- Call System.assertThrows() with the method reference
- Annotate the test method with @IsTest(expectException=true)
Correct answer: Wrap the call in a try/catch and assert inside the catch block
Apex tests verify exceptions by wrapping the call in try/catch and using System.assert() inside the catch to confirm the expected exception type and message.
Question 3: What is the maximum size of a single debug log file in Salesforce?
- 2 MB
- 5 MB
- 20 MB (Correct answer)
- 50 MB
Correct answer: 20 MB
A single Apex debug log can be up to 20 MB; logs exceeding this size are truncated and older entries are removed from the beginning.
Question 4: In Apex, which method is used to register a mock implementation for a Callable interface during testing?
- Test.setMock(Callable.class, mockInstance)
- Test.setMock(HttpCalloutMock.class, mockInstance)
- Test.stubCallable(mockInstance)
- Callable stubs must be set via dependency injection, not Test.setMock (Correct answer)
Correct answer: Callable stubs must be set via dependency injection, not Test.setMock
Callable mocks cannot be registered via Test.setMock(); they must be injected by passing the mock object directly to the class under test.
Question 5: When using the Developer Console's Checkpoint feature, what type of information can a developer inspect at a checkpoint line?
- Only the call stack at that line
- Variable values, heap contents, and iteration counts at that execution point (Correct answer)
- CPU time consumed up to that line only
- HTTP request/response pairs triggered before that line
Correct answer: Variable values, heap contents, and iteration counts at that execution point
Checkpoints in the Developer Console capture a snapshot of heap contents, variable values, and execution counts at that specific line during a transaction.
Question 6: A test class has the @isTest(SeeAllData=true) annotation. What is the primary risk of using this annotation?
- It causes all DML in the test to be committed permanently
- Tests may pass or fail depending on existing org data, reducing reliability (Correct answer)
- It disables all governor limits for the test class
- It exposes the test data to other test classes in the same run
Correct answer: Tests may pass or fail depending on existing org data, reducing reliability
SeeAllData=true makes tests dependent on live org data, so results vary across orgs or sandboxes, making tests fragile and unreliable.
Question 7: Which Apex class allows a developer to write a test that verifies an entire batch Apex job runs to completion?
- Database.BatchableContext
- Test.runAllTests()
- Test.stopTest() (Correct answer)
- AsyncOptions
Correct answer: Test.stopTest()
Calling Test.stopTest() forces all asynchronous operations—including batch jobs—queued between startTest/stopTest to execute synchronously before the method continues.
Which Limits method returns the number of SOQL queries issued in the current transaction so far?