PD1 Testing and Debugging 4 — Questions and Answers
Question 1: Which tool in Salesforce Setup allows a developer to view real-time debug logs for a specific user without using the Developer Console?
- Apex Test Execution page
- Debug Log section under Monitoring (Correct answer)
- Event Monitoring page
- Apex Jobs page
Correct answer: Debug Log section under Monitoring
The Debug Log section under Setup > Monitoring lets developers add trace flags and view or download debug logs for specific users or classes.
Question 2: A Queueable job is enqueued inside a test using System.enqueueJob(). When does it actually execute in the test?
- Immediately when enqueued, before the next line of the test
- After Test.stopTest() is called (Correct answer)
- Only if Test.runAllTests() is invoked
- It never executes inside a test — it must be mocked
Correct answer: After Test.stopTest() is called
Like other async jobs, a Queueable enqueued between Test.startTest() and Test.stopTest() executes synchronously when Test.stopTest() is called.
Question 3: A developer adds System.debug(LoggingLevel.ERROR, 'msg') to their code. At which log category level settings will this message appear?
- Only when the Apex log category is set to ERROR
- When the Apex log category is set to ERROR, WARN, INFO, DEBUG, FINE, FINER, or FINEST (Correct answer)
- Only when the Apex log category is set to FINEST
- Only when using the Developer Console — not in Setup debug logs
Correct answer: When the Apex log category is set to ERROR, WARN, INFO, DEBUG, FINE, FINER, or FINEST
LoggingLevel.ERROR messages appear at any log level equal to or more verbose than ERROR, which includes all standard Apex log levels.
Question 4: Which annotation must be placed on a test class or test method to allow it to run with the Apex test framework?
- @AuraEnabled
- @TestVisible
- @isTest (Correct answer)
- @RemoteAction
Correct answer: @isTest
@isTest marks a class or method as part of the test suite and prevents it from counting against the org's code size limit.
Question 5: What is the purpose of the @TestVisible annotation in Apex?
- It makes a private method callable from external classes in production
- It allows test classes to access private members of the class under test (Correct answer)
- It enables a test class to see all org data regardless of sharing rules
- It exposes a method for invocation from Flow or Process Builder during testing
Correct answer: It allows test classes to access private members of the class under test
@TestVisible allows private or protected methods and variables to be accessed by test classes without changing their access modifier in production code.
Question 6: In a Salesforce debug log, which event category would you expand to find details about Apex variable assignments and conditional branch decisions?
- DB
- CALLOUT
- APEX_CODE (Correct answer)
- VALIDATION
Correct answer: APEX_CODE
The APEX_CODE log category captures Apex execution events including variable assignments, method entries/exits, and branching logic.
Question 7: A developer uses Test.setFixedSearchResults() in a test method. What does this method do?
- It caches SOQL results to prevent redundant queries during the test
- It specifies a fixed list of record IDs returned by SOSL searches in the test (Correct answer)
- It sets the order in which records are returned by SOQL ORDER BY clauses
- It mocks the output of a Named Credential HTTP response
Correct answer: It specifies a fixed list of record IDs returned by SOSL searches in the test
Test.setFixedSearchResults() predefines which record IDs a SOSL query will return during a test, since real search indexes are not available in test context.
Which tool in Salesforce Setup allows a developer to view real-time debug logs for a specific user without using the Developer Console?