Praxis Academy
Home › Platform Developer II › Testing, Debugging, and Deployment

Platform Developer II practice questions: Testing, Debugging, and Deployment

Testing, Debugging, and Deployment is 20% of the Salesforce Certified Platform Developer II exam. It covers test data, callout mocks, async tests, debug logs, Salesforce CLI and packages. Try these 15 free questions, then open each answer to see why every option is right or wrong.

01

A logistics company has a test class with a @testSetup method that inserts 50 Shipment__c records. testA deletes 10 of them and testB counts the records. What count does testB see?

  1. 40, because testA ran first and its deletes persisted
  2. 50, because each test method gets a fresh copy of the @testSetup data
  3. 0, because @testSetup data is only visible to the first test method
  4. It depends on the alphabetical order in which methods run
Show answer

Answer: B

A. 40, because testA ran first and its deletes persistedTest methods do not share DML changes; each method's changes are rolled back before the next one runs.
B. 50, because each test method gets a fresh copy of the @testSetup data ✓Correct. Records created in @testSetup are rolled back to their original state after each test method, so every method starts with the same data.
C. 0, because @testSetup data is only visible to the first test method@testSetup data is available to every test method in the class, not only the first.
D. It depends on the alphabetical order in which methods runExecution order is not guaranteed, but it does not matter here because each method is isolated.

Why: A @testSetup method runs once per class, and its records are reset for each test method. Changes made by one test method are never visible to another.

02

A developer writes a test for a Database.Batchable class with a batch size of 200. The test inserts 500 records and calls Database.executeBatch inside Test.startTest/Test.stopTest. The test fails. What is the most likely cause?

  1. Batch Apex cannot be tested; it must be validated in a sandbox manually
  2. Database.executeBatch must be called before Test.startTest to work
  3. A test can run only one execute invocation, so it should insert no more records than the batch size
  4. The batch class must implement Database.Stateful to run in tests
Show answer

Answer: C

A. Batch Apex cannot be tested; it must be validated in a sandbox manuallyBatch Apex can be tested by running it between Test.startTest and Test.stopTest.
B. Database.executeBatch must be called before Test.startTest to workThe batch must be started after Test.startTest so that stopTest forces it to complete.
C. A test can run only one execute invocation, so it should insert no more records than the batch size ✓Correct. In a test, only one execution of the execute method is allowed, so the test data must fit in a single batch scope.
D. The batch class must implement Database.Stateful to run in testsDatabase.Stateful preserves state across batches; it is not required for testing.

Why: When testing batch Apex, limit the test data (or the scope parameter) so that execute runs only once, and run the batch between Test.startTest and Test.stopTest.

03

A test inserts a User with a specific Role and then inserts an Account in the same test method. It fails with a MIXED_DML_OPERATION error. What is the simplest fix inside the test?

  1. Insert the Account first and the User second in the same context
  2. Perform the Account insert inside a System.runAs block
  3. Use Database.insert with allOrNone set to false for both records
  4. Add @isTest(SeeAllData=true) and use an existing User
Show answer

Answer: B

A. Insert the Account first and the User second in the same contextThe order does not matter; setup and non-setup DML in the same context still cause the error.
B. Perform the Account insert inside a System.runAs block ✓Correct. Wrapping one of the DML operations in System.runAs separates the setup and non-setup operations, avoiding the mixed DML error in tests.
C. Use Database.insert with allOrNone set to false for both recordsPartial success does not change the restriction on mixing setup and non-setup objects.
D. Add @isTest(SeeAllData=true) and use an existing UserThis avoids the insert but couples the test to org data, which is not the recommended fix.

Why: Setup objects (like User with a Role) and non-setup objects cannot be modified in the same transaction. In tests, System.runAs creates a separate context to avoid MIXED_DML_OPERATION.

04

A shipping integration calls two endpoints in one transaction: one for rates and one for label creation. The developer has stored a JSON response for each endpoint as a static resource. Which mock is the most efficient choice for the test?

  1. StaticResourceCalloutMock with both responses in one static resource
  2. Two Test.setMock calls, one per endpoint, with HttpCalloutMock
  3. MultiStaticResourceCalloutMock with setStaticResource for each endpoint URL
  4. WebServiceMock with a branch for each endpoint
Show answer

Answer: C

A. StaticResourceCalloutMock with both responses in one static resourceStaticResourceCalloutMock returns a single response for every callout, so it cannot vary by endpoint.
B. Two Test.setMock calls, one per endpoint, with HttpCalloutMockOnly the last mock registered for a type is active, so two calls do not route by endpoint.
C. MultiStaticResourceCalloutMock with setStaticResource for each endpoint URL ✓Correct. MultiStaticResourceCalloutMock maps each endpoint to its own static resource response.
D. WebServiceMock with a branch for each endpointWebServiceMock is for SOAP callouts from WSDL2Apex classes, not REST HTTP requests.

Why: MultiStaticResourceCalloutMock lets a test return different static resource responses per endpoint, with status code and headers set once for all of them.

05

A payments class contains: if (Test.isRunningTest()) { result = 'APPROVED'; } else { result = gateway.charge(amount); } A reviewer flags it as a poor practice. Which refactor best supports testing?

  1. Wrap the gateway call in a try/catch and return 'APPROVED' when it fails
  2. Move the Test.isRunningTest check into a separate utility method
  3. Mark the gateway variable with @TestVisible and leave the branch in place
  4. Inject the gateway through an interface so the test can pass a mock implementation
Show answer

Answer: D

A. Wrap the gateway call in a try/catch and return 'APPROVED' when it failsSwallowing errors hides real failures in production and does not make the code testable.
B. Move the Test.isRunningTest check into a separate utility methodRelocating the check keeps test-only logic in production code.
C. Mark the gateway variable with @TestVisible and leave the branch in place@TestVisible exposes members to tests but does not remove the test-only branch.
D. Inject the gateway through an interface so the test can pass a mock implementation ✓Correct. Dependency injection lets tests supply a fake gateway, so production code has no test-only branches.

Why: Test.isRunningTest branches mean tests never run the real logic. Depending on an interface and injecting a mock (or a Stub API stub) keeps production code clean and fully testable.

06

A class has a private static Map<Id, Decimal> rateCache used for performance. A test needs to pre-populate the cache to verify the cache-hit path, but the developer does not want to make the map public. What should the developer use?

  1. Declare the test class as an inner class of the production class
  2. Use the Stub API to mock the private map
  3. Annotate the map with @TestVisible
  4. Change the map to protected and extend the class in the test
Show answer

Answer: C

A. Declare the test class as an inner class of the production classTest methods cannot be defined in inner classes of non-test classes.
B. Use the Stub API to mock the private mapThe Stub API cannot mock private members or properties.
C. Annotate the map with @TestVisible ✓Correct. @TestVisible lets test methods access private or protected members without changing their visibility for other code.
D. Change the map to protected and extend the class in the testThis changes production visibility and does not apply to static members in the way needed.

Why: @TestVisible exposes private or protected members only to test code, so tests can inspect or set internal state without widening the production API.

07

A developer is investigating why a collection in a long trigger handler contains unexpected values. She wants to inspect the heap state at specific lines in the Developer Console without changing the code. What should she use?

  1. System.debug statements on each line
  2. Checkpoints set on the relevant lines, then review the heap dump in the Checkpoints tab
  3. The Query Plan tool for the SOQL inside the handler
  4. A Flow debug run on the Account object
Show answer

Answer: B

A. System.debug statements on each lineAdding System.debug changes the code, which she wants to avoid.
B. Checkpoints set on the relevant lines, then review the heap dump in the Checkpoints tab ✓Correct. Developer Console checkpoints capture heap and variable state at specific lines when the code runs, without editing the code.
C. The Query Plan tool for the SOQL inside the handlerQuery Plan shows SOQL selectivity and cost, not variable state.
D. A Flow debug run on the Account objectFlow debugging does not inspect Apex variables.

Why: Developer Console checkpoints (up to five at a time) capture a snapshot of objects in memory at a line of code. They are reviewed in the Checkpoints tab after the code runs.

08

A bulk import fails with System.LimitException: Too many SOQL queries: 101. The developer wraps the import loop in try/catch(Exception e) to log the error and continue, but the transaction still fails. Why?

  1. The catch block must specify QueryException instead of Exception
  2. try/catch blocks are not allowed inside loops
  3. System.LimitException cannot be caught; the code must be bulkified to avoid the limit
  4. The catch block must call Database.rollback to continue
Show answer

Answer: C

A. The catch block must specify QueryException instead of ExceptionQueryException is a different type; LimitException would still not be caught.
B. try/catch blocks are not allowed inside loopstry/catch can be used inside loops; that is not the problem.
C. System.LimitException cannot be caught; the code must be bulkified to avoid the limit ✓Correct. Governor limit exceptions cannot be handled, so the fix is to move SOQL out of the loop.
D. The catch block must call Database.rollback to continueRolling back does not prevent or handle a LimitException.

Why: LimitException terminates the transaction and cannot be caught. Prevent it by bulkifying code and checking Limits methods when needed.

09

A healthcare company needs a sandbox for performance and load testing that contains all production data and metadata. It plans to refresh it about once a month. Which sandbox type fits?

  1. Developer Pro sandbox
  2. Partial Copy sandbox
  3. Developer sandbox
  4. Full sandbox
Show answer

Answer: D

A. Developer Pro sandboxDeveloper Pro copies metadata only, with limited storage, so it cannot hold all production data.
B. Partial Copy sandboxPartial Copy includes a sample of data defined by a sandbox template, not all production data.
C. Developer sandboxDeveloper sandboxes have small storage and no production data copy.
D. Full sandbox ✓Correct. A Full sandbox copies all data and metadata and can be refreshed every 29 days, which suits performance and load testing.

Why: Full sandboxes replicate production data and metadata and have a 29-day refresh interval. Partial Copy sandboxes include sampled data and refresh every 5 days; Developer sandboxes refresh daily.

10

A developer deploys a hotfix to production that includes one Apex class and its test class. To reduce deployment time, she wants to run only that test. Which command is appropriate?

  1. sf project deploy start --source-dir force-app --test-level RunLocalTests
  2. sf project deploy start --source-dir force-app --test-level NoTestRun
  3. sf project deploy start --source-dir force-app --test-level RunAllTestsInOrg
  4. sf project deploy start --source-dir force-app --test-level RunSpecifiedTests --tests HotfixServiceTest
Show answer

Answer: D

A. sf project deploy start --source-dir force-app --test-level RunLocalTestsRunLocalTests runs all local tests in the org, which is what she wants to avoid.
B. sf project deploy start --source-dir force-app --test-level NoTestRunNoTestRun is not permitted for production deployments containing Apex.
C. sf project deploy start --source-dir force-app --test-level RunAllTestsInOrgThis runs every test, including managed package tests, and is the slowest option.
D. sf project deploy start --source-dir force-app --test-level RunSpecifiedTests --tests HotfixServiceTest ✓Correct. RunSpecifiedTests runs only the named tests, which must give each deployed class and trigger at least 75% coverage.

Why: With RunSpecifiedTests, only the listed tests run, and the coverage requirement is calculated per deployed class and trigger (75% each) rather than for the whole org.

11

A team builds an unlocked package for its internal billing app. A package version was created successfully, but promoting it to released fails. What is the most likely reason?

  1. The package has no namespace
  2. Unlocked package versions cannot be promoted; only managed packages can be released
  3. The version was created in a scratch org instead of the Dev Hub
  4. The version was created without --code-coverage, or its Apex coverage is below 75%
Show answer

Answer: D

A. The package has no namespaceUnlocked packages can be created and released without a namespace.
B. Unlocked package versions cannot be promoted; only managed packages can be releasedUnlocked package versions can be promoted to released.
C. The version was created in a scratch org instead of the Dev HubPackage versions are created through the Dev Hub, not in a scratch org, so that is not the cause.
D. The version was created without --code-coverage, or its Apex coverage is below 75% ✓Correct. A package version must be created with code coverage calculated and have at least 75% Apex coverage to be promoted.

Why: Before promoting a package version to released, create it with the --code-coverage flag. Promotion requires at least 75% Apex code coverage.

12

A QA lead wants to run the same set of 25 regression test classes after every sandbox deployment, without selecting them one by one each time. What should the developer create?

  1. A custom permission that marks the classes as regression tests
  2. A package.xml listing the test classes
  3. A @testSetup method shared by all 25 classes
  4. An Apex test suite containing the 25 classes
Show answer

Answer: D

A. A custom permission that marks the classes as regression testsCustom permissions control user access, not test grouping.
B. A package.xml listing the test classesA manifest controls deployment content; it does not group tests for runs.
C. A @testSetup method shared by all 25 classes@testSetup creates data within a single class and does not group classes.
D. An Apex test suite containing the 25 classes ✓Correct. Test suites group test classes so they can be run together from Developer Console, Setup, or CLI.

Why: Apex test suites are named collections of test classes that can be run repeatedly, for example with sf apex run test --suite-names.

13

A team's test classes each build Accounts, Contacts, and Opportunities with slightly different hardcoded values, and a new required field broke 40 tests. The architect asks for a TestDataFactory class. Which two design choices are best practices? (Choose 2)

  1. Annotate the factory with @isTest(SeeAllData=true) so it can reuse existing records
  2. Annotate the factory class with @isTest so it does not count against the org's Apex code size limit
  3. Make every factory method insert records immediately with no option to skip DML
  4. Put the factory methods in the production trigger handler for reuse
  5. Provide methods that accept a record count and a flag for whether to insert, with required fields set in one place
Show answer

Answer: B, E

A. Annotate the factory with @isTest(SeeAllData=true) so it can reuse existing recordsFactories should create data, not depend on org data; SeeAllData makes tests fragile.
B. Annotate the factory class with @isTest so it does not count against the org's Apex code size limit ✓Correct. A public @isTest utility class is accessible only from tests and is excluded from the code size limit.
C. Make every factory method insert records immediately with no option to skip DMLAlways inserting prevents tests from changing fields before insert or testing insert logic themselves.
D. Put the factory methods in the production trigger handler for reuseMixing test utilities into production code adds untested paths and clutter.
E. Provide methods that accept a record count and a flag for whether to insert, with required fields set in one place ✓Correct. Central defaults with count and insert parameters let tests create bulk data and adapt quickly when required fields change.

Why: A TestDataFactory centralizes valid default values, supports bulk creation, and lets callers decide whether to insert. Annotating it with @isTest keeps it out of the code size limit.

14

A Visualforce page uses a Continuation to call a slow credit bureau service. How should the developer test the controller's callback method?

  1. Use HttpCalloutMock with Test.setMock, because Continuations use the same mock
  2. Call the callback method directly with a null state object
  3. Use Test.setContinuationResponse for the request label, then call Test.invokeContinuationMethod
  4. Wrap the action in Test.startTest/Test.stopTest so the Continuation completes
Show answer

Answer: C

A. Use HttpCalloutMock with Test.setMock, because Continuations use the same mockContinuation requests are not answered by HttpCalloutMock; they have a dedicated testing API.
B. Call the callback method directly with a null state objectThis skips the continuation flow and does not provide a response for the request label.
C. Use Test.setContinuationResponse for the request label, then call Test.invokeContinuationMethod ✓Correct. setContinuationResponse sets the mock response and invokeContinuationMethod runs the callback as the platform would.
D. Wrap the action in Test.startTest/Test.stopTest so the Continuation completesstopTest completes async Apex jobs, not Continuation callouts.

Why: Continuations are tested by setting a fake response with Test.setContinuationResponse and invoking the callback with Test.invokeContinuationMethod.

15

A Queueable class that implements Database.AllowsCallouts posts order data to an ERP and updates the Order status from the response. The test sets the mock and enqueues the job but asserts on the status before Test.stopTest. The assertion fails. What should change?

  1. Remove Database.AllowsCallouts because callouts are mocked in tests
  2. Call the job's execute method twice to process the response
  3. Use Test.setMock after Test.stopTest so the mock is active when the job runs
  4. Move the assertion after Test.stopTest, so the queued job and its mocked callout have completed
Show answer

Answer: D

A. Remove Database.AllowsCallouts because callouts are mocked in testsThe interface is still required for the Queueable to make callouts, mocked or not.
B. Call the job's execute method twice to process the responseCalling execute manually does not fix the timing of the assertion and duplicates processing.
C. Use Test.setMock after Test.stopTest so the mock is active when the job runsThe mock must be registered before the job runs at stopTest, or the callout fails.
D. Move the assertion after Test.stopTest, so the queued job and its mocked callout have completed ✓Correct. The Queueable runs at Test.stopTest, so results are available only after that call.

Why: Queueables with callouts are tested by setting the mock, enqueuing inside Test.startTest/Test.stopTest, and asserting only after stopTest when the job has run.

Find out if you're ready to pass

Take the free Platform Developer II diagnostic: 20 questions, no account needed. Then unlock all 300 questions, full practice exams and the study guide.

Start the free diagnosticSee plans

Other sections of this exam