What must be true for a developer to deploy Apex code to a production environment?
This is the mandatory requirement for production deployments.
Why this answer
The code must have at least 75% coverage and all tests must pass.
75 of 107 questions · Page 1/2 · Testing Debugging And Deployment · Answers revealed
What must be true for a developer to deploy Apex code to a production environment?
This is the mandatory requirement for production deployments.
Why this answer
The code must have at least 75% coverage and all tests must pass.
A developer wants to test an asynchronous future method. Where must the developer place the asynchronous code execution so that it runs synchronously and within the test context?
Placing code between startTest and stopTest resets governor limits and forces async processing to complete.
Why this answer
Test.startTest() and Test.stopTest() bracket the code block where asynchronous processes like future methods, batch jobs, and queueables are forced to execute synchronously.
A developer needs to access private methods in an Apex class for unit testing without making them public. Which annotation is the most appropriate?
This allows test methods to access the private or protected members of a class.
Why this answer
@TestVisible allows test classes to access private and protected members of a class.
A developer is deploying metadata from a sandbox to a production org using Salesforce CLI. Which command should the developer use to validate the deployment without actually saving components to the target organization?
The --dry-run flag validates the deployment against the target org without making permanent changes.
Why this answer
The sf project deploy start command includes a dry-run or check-only validation flag. In modern Salesforce CLI (sf), it is --dry-run.
When deploying via Metadata API, what happens if a test class fails during the deployment?
Transactional deployment ensures no partial changes if tests fail.
Why this answer
The entire deployment fails by default unless specified otherwise.
A developer has written a test method that requires a large volume of test data to be set up. To avoid writing duplicate data setup code across multiple test methods in the same class, which annotation should the developer use?
TestSetup is used to create test records once and roll back changes between test methods automatically.
Why this answer
The @TestVisible annotation is incorrect for data setup. The @TestSetup annotation executes once per test class and creates data for all test methods in that class.
Why must you use Test.startTest() when testing asynchronous Apex code?
Test.stopTest triggers all queued asynchronous jobs.
Why this answer
Asynchronous code like @future or Queueable is queued; Test.startTest ensures it executes when Test.stopTest is called.
A developer is writing a unit test and needs to assert that a specific custom exception was thrown during invalid input processing. Which pattern should the developer use?
Placing Assert.fail after the code ensures that if the exception is not thrown, the test fails immediately.
Why this answer
Using try-catch blocks with System.assert or Assert.fail inside the try block ensures that if the exception is not thrown, the test fails.
A developer is writing a test class that requires several custom objects to be populated with data. What is the most efficient way to handle this across multiple test methods?
This annotation ensures data is inserted once for all test methods in the class.
Why this answer
The @TestSetup annotation allows creating data once for all test methods within a class, reducing execution time.
Which TWO circumstances will cause an Apex unit test method to fail? (Choose two.)
Failed assertions throw an exception that fails the test method.
Why this answer
Uncaught exceptions and failed system assertions cause test method failures.
A developer needs to write a test class for an Apex class that performs DML operations. Which annotation must be used to define the class as a test class?
The @isTest annotation is the standard way to define test classes.
Why this answer
The @isTest annotation is required to define a class as a test class in Apex.
Which log level is best for finding logic flow issues without cluttering the log?
Appropriate balance.
Why this answer
DEBUG is the standard level for custom messages and logic tracing.
What is the primary function of a scratch org?
They are designed for CI/CD and source-based workflows.
Why this answer
A scratch org is an ephemeral, configurable Salesforce environment for development and testing.
When is an Apex test run automatically executed?
Mandatory check.
Why this answer
Tests are run automatically during deployment and package installation.
When debugging a trigger, how can you view the flow of execution including entry and exit points of methods?
Shows method nesting.
Why this answer
The Call Stack in the Debug Log shows the hierarchy of method calls.
A developer is debugging a process that involves asynchronous Apex. Which Debug Log setting is required to see the output of the @future method?
This ensures Apex statements are captured in the log.
Why this answer
Setting the Apex Code level to DEBUG is necessary to see standard logs.
Which TWO conditions must be met for an Apex test method to successfully execute and contribute to code coverage? (Choose two.)
Test methods must be static.
Why this answer
Test methods must be static, have a void return type, and be marked with @isTest.
Why might a deployment fail due to 'Apex classes do not have sufficient coverage'?
Total coverage is the requirement.
Why this answer
The combined coverage across all classes must be at least 75%.
Which THREE of the following are benefits of using the Salesforce CLI for deployment?
CLI commands can be scripted for CI/CD.
Why this answer
CLI offers automation, version control integration, and environment consistency.
Which TWO tools or APIs can a developer use to deploy metadata between Salesforce organizations? (Choose two.)
Change sets are native point-and-click tools for moving metadata between connected orgs.
Why this answer
Change Sets and the Metadata API (via CLI or IDEs) are primary tools for metadata deployment.
A developer needs to test a feature that relies on the current time. Which method should be used to simulate time?
Dependency injection is the only way to mock time.
Why this answer
There is no built-in way to 'freeze' time; developers should design for dependency injection of time, but the question asks for standard tools.
A developer wants to view real-time debug log streaming in their local environment using the Salesforce CLI. Which command should the developer execute?
sf apex log tail streams logs in real-time to the command line.
Why this answer
The sf apex tail log command streams debug logs to the terminal in real time.
Why should a developer ensure that test classes have at least 75% coverage for production deployment?
Mandatory deployment requirement.
Why this answer
The platform requires at least 75% code coverage for all Apex classes before they can be deployed to production.
A developer wants to ensure that specific test data is available to all test methods in a class without recreating it. Which method should be used?
@testSetup creates data once for all test methods in the class.
Why this answer
@testSetup methods are executed once per class and set up data for all methods.
A developer has written a Lightning Web Component and Apex controller, and wants to deploy only these specific metadata components to a production org using Salesforce CLI without relying on change sets. Which command is appropriate?
sf project deploy start deploys metadata to a target org from the local project.
Why this answer
sf project deploy start deploys source files from a local project directory to a target org.
When using the Metadata API to deploy components, which XML file must be present to define the components included in the package?
This is the required manifest file for Metadata API operations.
Why this answer
The 'package.xml' file is the manifest that lists the components to be retrieved or deployed via the Metadata API.
Where should a developer look in the Salesforce user interface to inspect detailed system debug logs generated during a specific transaction?
Setup > Custom Code > Debug Logs lists all captured debug logs for users and traces.
Why this answer
Debug logs are accessed via Setup by navigating to Custom Code > Debug Logs or via the Developer Console.
When calling Test.startTest() and Test.stopTest(), what happens to the governor limits?
This allows for testing code that might hit limits individually.
Why this answer
Test.startTest and Test.stopTest reset governor limits within the block.
Which approach is recommended to ensure test data is cleaned up?
This ensures no data side effects.
Why this answer
Salesforce automatically rolls back all data created in a test method after completion.
You need to inspect the heap size during the execution of a long-running batch job. Which debug log category should you monitor?
Profiling is specifically designed for monitoring resource consumption.
Why this answer
The Profiling category logs governor limit usage, including heap size and CPU time.
Which TWO of the following are true about the 'Debug Log' settings in the Setup menu?
Trace flags must be defined with an expiration window.
Why this answer
Logs can be set for users, and the duration of those log traces is limited.
A developer is writing a test for a method that performs a callout. How must the callout be handled?
Standard practice for testing callouts.
Why this answer
Callouts must be mocked using HttpCalloutMock to avoid external network dependencies.
Which TWO of the following are limitations when deploying using the Metadata API?
A manifest is required for Metadata API.
Why this answer
Metadata API deployments require a manifest file and are subject to the same validation rules as the org.
A developer needs to write a unit test to verify that a trigger correctly inserts related Task records when a custom object record is created. Which annotation should the developer place on the test class method to ensure it runs correctly and can access existing org data if needed?
The @isTest annotation is required on test classes and test methods to define them for execution.
Why this answer
The @isTest annotation identifies a method or class as containing unit tests. Using @isTest(SeeAllData=true) is sometimes required when legacy data must be accessed, though best practice is to create test data locally.
When deploying metadata from a sandbox to production using Change Sets, what is the first requirement?
Deployment connections are mandatory for moving Change Sets between environments.
Why this answer
A Deployment Connection must be established between the two organizations before a Change Set can be sent.
A developer is writing a unit test that executes under a specific user context to verify sharing rules. Which method should the developer use to specify the user for the subsequent test operations?
System.runAs allows block-level execution under a specified User instance to test sharing behavior.
Why this answer
System.runAs() enables developers to run test methods under a specific user context to verify record-level security and sharing rules.
What happens if a developer creates a test method that does not contain any assertions?
Tests require assertions to be meaningful.
Why this answer
The test will pass as long as the code runs without error, but it is not a valid test.
Which of the following is a limitation of Change Sets?
Change Sets require a deployment connection between the source and target orgs.
Why this answer
Change Sets are strictly one-way and cannot be used to deploy changes from production back to a sandbox.
A developer is writing a test method that performs a callout to an external REST service. Which interface must the developer implement to provide mock responses during the unit test execution?
HttpCalloutMock must be implemented to return fake responses since actual callouts are not permitted in test methods.
Why this answer
HttpCalloutMock is the interface implemented to supply a mock HTTP response during test context when callouts are made.
A developer needs to see how much memory a specific Apex method is consuming. Which log category should be adjusted?
Profiling provides memory and resource usage data.
Why this answer
The Profiling category provides detailed information on resource consumption.
A developer wants to log information specifically when a condition is met. Which method is most appropriate?
Correct method for adding logs.
Why this answer
System.debug() is used to add custom messages to the debug log.
A developer is writing an Apex test class and needs to reset governor limits before executing a block of asynchronous code testing. Which method should the developer use?
Test.startTest() marks the point when test execution begins and resets governor limits.
Why this answer
Test.startTest() and Test.stopTest() bracket the test section, resetting governor limits for the execution block within them and forcing any asynchronous calls to run synchronously.
An asynchronous @future method is called from within an Apex test method. When are the statements inside the @future method actually executed during the test run?
Test.stopTest collects all asynchronous processes and runs them synchronously before resuming test execution.
Why this answer
Asynchronous methods called in tests are queued and executed synchronously after the Test.stopTest() statement.
A developer is troubleshooting a complex set of triggers and wants to restrict the amount of debug log data captured for a specific integration user. Which THREE actions can the developer take to manage debug logs effectively? (Choose three.)
Debug levels define the granularity of logs recorded per category.
Why this answer
Trace flags control log levels and duration for users, classes, or triggers. Log categories allow filtering verbosity.
What is the maximum number of debug logs that can be stored per user?
Based on aggregate size.
Why this answer
There is a limit (typically 50MB per user, but logs are replaced).
A developer needs to verify that a trigger correctly handles bulk data, specifically 250 records. What is the most effective approach?
Inserting a collection of records is the standard way to test bulk DML operations.
Why this answer
Testing with a collection of records validates bulkification and prevents governor limit exceptions.
Where can a developer view the generated debug logs for an Apex execution in the Salesforce UI?
This is the correct navigation path for viewing logs.
Why this answer
Debug logs are accessible via the Setup menu under 'Debug Logs' or within the Developer Console.
What is the primary function of the 'Developer Console'?
Primary purpose.
Why this answer
It is an integrated development environment for writing, debugging, and testing Apex.
A developer is receiving 'Too many SOQL queries' errors in a trigger. What is the most likely cause?
This hits the query limit quickly.
Why this answer
Performing SOQL inside a loop is the primary cause of this error.
Which tool is best suited for migrating metadata between two related Salesforce Orgs using a UI-based approach?
Change Sets provide a UI for moving metadata between linked Orgs.
Why this answer
Change Sets are designed for moving metadata between linked Salesforce Orgs.
What is the result of a compilation error in an Apex class during deployment?
Deployment is transactional.
Why this answer
Compilation errors prevent deployment.
If a developer uses 'SeeAllData=true' in a test class, what are the primary risks?
This leads to 'brittle' tests that fail if data changes.
Why this answer
It relies on existing organization data, making tests brittle and dependent on external state.
Which THREE statements are true regarding Salesforce debug logs? (Choose three.)
Debug logs track multiple categories including Database, ApexCode, and Workflow.
Why this answer
Debug logs capture system events, have size limits, and require trace flags.
A developer needs to reset the governor limits within a test method to verify functionality that processes large amounts of records. Which method should be used?
Test.startTest() resets limits, and the code following Test.stopTest() is executed with fresh limits.
Why this answer
Test.startTest() and Test.stopTest() reset the governor limits for the code executed between them.
How can a developer identify the most time-consuming SOQL query in a transaction?
Logs capture duration.
Why this answer
By checking the 'Executed Units' or 'SOQL' section of the debug log for duration.
What is the purpose of the 'Debug Log' Filter in the Developer Console?
Primary purpose.
Why this answer
It allows developers to focus on specific categories or levels of logs.
Which TWO actions occur automatically when Test.stopTest() is called in an Apex unit test? (Choose two.)
StopTest forces all asynchronous processes to execute before proceeding.
Why this answer
Test.stopTest() executes asynchronous jobs and processes pending communications.
When deploying code using Unmanaged Change Sets between connected Salesforce organizations, which TWO limitations or behaviors apply? (Choose two.)
Standard objects and standard fields have restrictions regarding inclusion in change sets.
Why this answer
Change sets require inbound connection approval, and certain components require manual post-deployment steps or cannot be included.
When testing a class that depends on Custom Settings, what is the best practice?
Best practice for test independence.
Why this answer
Create the custom settings in the test method setup to ensure independence from production data.
You are using the Salesforce CLI to deploy code. Which command is used to deploy source code from a local project to an org?
This command deploys the source code to the target org.
Why this answer
The 'sf project deploy start' command is the current standard for deploying source to an org.
Which THREE items are included in a debug log?
Custom debug messages are included.
Why this answer
Debug logs contain execution details for DML, SOQL, and custom user debug messages.
Which TWO of the following are valid ways to execute Apex unit tests in Salesforce?
The Developer Console is a primary tool for test execution.
Why this answer
Tests can be run via the Developer Console or the Apex Test Execution page in Setup.
Why does a test fail if it tries to perform a callout without Test.setMock()?
Prevents external dependencies.
Why this answer
Salesforce blocks all real callouts in tests to prevent side effects.
Which THREE of the following items can be viewed in a debug log?
DML activity is recorded.
Why this answer
Debug logs track database actions, Apex code, and workflow execution.
A developer is preparing to deploy metadata changes from a sandbox to a production org using Outbound Change Sets. Where must the administrator or developer establish the connection between the two organizations?
Inbound change sets require deployment connections to be authorized and deployed from trusted source orgs via Deployment Settings.
Why this answer
Deployment connections for change sets must be authorized and configured in Deployment Settings in the target production org.
A developer is analyzing a debug log and notices that it is truncated because it exceeded the maximum file size limit. Which action should the developer take to capture only the relevant Apex code execution details without exceeding the limit?
Reducing verbosity for unneeded categories keeps log sizes small enough to capture the critical execution path.
Why this answer
Refining log categories and levels ensures only necessary debug statements are recorded, preventing truncation.
What is the primary purpose of the Salesforce CLI in a CI/CD pipeline?
CLI facilitates source-driven development and automation.
Why this answer
The Salesforce CLI is the fundamental tool for programmatically interacting with Salesforce Orgs in automation.
Which THREE actions are best practices when deploying Apex classes to production?
Ensures no regressions.
Why this answer
Running tests, validating, and using version control are key deployment practices.
A developer needs to check the status of a long-running batch job that was triggered by an Apex class. Where should they look?
Displays status for async jobs.
Why this answer
The Apex Jobs page lists all batch, future, and queueable jobs.
Which TWO practices are considered best practices when writing Apex unit tests in Salesforce? (Choose two.)
Creating test data locally ensures test independence and reliability.
Why this answer
Using Test.startTest/stopTest and avoiding SeeAllData=true are essential Apex testing best practices.
What is a 'Change Set' used for?
Primary use case.
Why this answer
Change Sets move metadata between connected Salesforce Orgs.
Which THREE features are supported in Salesforce scratch orgs? (Choose three.)
Packages can be installed into scratch orgs for testing dependencies.
Why this answer
Scratch orgs support source tracking, custom configurations, and feature activation.
Which TWO of the following are valid ways to specify which tests to run in the Salesforce CLI?
Using -c runs all tests in the package.
Why this answer
The CLI allows running specific classes or classes within a namespace.
A developer needs to measure the performance of a SOQL query. Which log category and level should be used?
Captures query performance.
Why this answer
The Database category at the INFO level or higher captures SOQL execution metrics.
Which TWO of the following are required to successfully use the 'Test.startTest()' and 'Test.stopTest()' pattern for testing batch Apex?
Assertions must wait until the asynchronous work is processed by stopTest.
Why this answer
This pattern is required to force the batch to execute within the test context and ensure it completes before assertions.
Ready to test yourself?
Try a timed practice session using only Testing Debugging And Deployment questions.