Courseiva

SF-PD2 · domain

Testing, Debugging, and Deployment

This domain covers Apex testing patterns, debugging tools, and deployment mechanics on the Salesforce Platform. Questions present realistic developer scenarios and ask you to select the correct tool, test approach, or deployment practice, so you must know when to use Developer Console, checkpoints, debug logs, Test.startTest/stopTest, and Salesforce DX commands.

59 questions10 easy26 medium23 hard

Focused practice

Practice Testing, Debugging, and Deployment questions

Scored sessions drawing only from this domain — pick a length below.

Start 20-question practice test →

What this domain covers

What to know about Testing, Debugging, and Deployment

Be able to write Apex tests that isolate data, create users with System.runAs, and verify asynchronous logic by wrapping it in Test.startTest and Test.stopTest. For deployment, use Salesforce DX with version control and scratch orgs so releases are repeatable and validated before production.

Using Developer Console checkpoints and debug logs to inspect variables and trace execution paths

Testing asynchronous Apex with Test.startTest and Test.stopTest to force background job execution

Creating test users with System.runAs and required profile or permission set access

Salesforce DX deployment practices including scratch orgs, unlocked packages, and source tracking

Watch out for

Common Testing, Debugging, and Deployment exam traps

  • ▸Assuming asynchronous Apex runs during a test without wrapping it in Test.startTest and Test.stopTest, so assertions execute before the job finishes
  • ▸Querying or creating users directly in tests instead of using System.runAs with a properly configured test user and permissions
  • ▸Treating change sets or manual metadata retrieval as repeatable deployment methods instead of using Salesforce DX source tracking and version control

Question index

All Testing, Debugging, and Deployment questions (59)

Click any question to see the full explanation, or start a practice session above.

1

A developer is preparing a managed package for release and needs to validate that the package's Apex code does not exceed the per-transaction limits enforced by the platform. The developer wants to run the packaged test suite in a scratch org and see the exact number of SOQL queries and DML statements consumed during each test. Which approach best satisfies this requirement?

Medium
2

A developer is preparing an Apex test class that must cover a service which schedules a Queueable job, and the test must verify that the queued job's logic actually ran and updated a record. The developer also needs the test to pass reliably in a CI pipeline. (Choose two.)

Hard
3

A developer is preparing to deploy a change set from a sandbox to production. The change set includes an Apex class that references a new custom field on Account. The deployment fails with a 'field does not exist' error. What is the most likely cause and the correct action?

Hard
4

A developer is debugging an Apex class that is failing in production. The developer wants to capture debug logs for a specific user without affecting other users. Which tool should be used to set up a trace flag for that user?

Hard
5

A developer has written an Apex class that includes a method to calculate shipping costs. The method contains several conditional branches. The developer wants to ensure that all branches are tested and that the test class provides sufficient coverage for deployment. Which Salesforce feature should the developer use to identify which lines of code are not covered by tests?

Easy
6

A developer is using the Salesforce CLI to deploy a set of Apex classes and a custom object to a sandbox. The developer wants to validate the deployment without saving any changes to the target org. Which command should the developer use?

Easy
7

A developer needs to measure the performance of a specific Apex code block in production. Which tool should be used to analyze CPU time without impacting end-user experience?

Hard
8

A developer is writing an Apex test method for a service class that makes a callout to an external REST API. The test must not perform the actual callout. The developer creates a static resource containing the JSON response and writes a mock class that implements HttpCalloutMock. Which statement must the developer include in the test method to register the mock before the callout is executed?

Medium
9

Refer to the exhibit. A developer encounters this LimitException in a bulkified trigger. What is the most likely cause based on the provided stack trace?

Hard
10

Refer to the exhibit. A developer encounters this error while performing a bulk update of 200 Account records. What is the root cause of this exception?

Medium
11

A developer needs to deploy a new Apex class to production that makes a callout to an external REST service. The callout must be made from a trigger. During testing in a sandbox, the developer writes a test class that performs DML to insert a record that fires the trigger, but the test fails with a 'CalloutException: Methods defined as TestMethod do not support Web service callouts' error. What should the developer do to allow the test to execute the callout successfully?

Medium
12

A developer is deploying a new Lightning web component that calls an Apex controller method. The deployment to production fails because the Apex class is not covered by tests. The developer needs to ensure the Apex class meets the 75% test coverage requirement and that the tests are robust. Which two actions should the developer take to achieve this? (Choose two.)

Medium
13

Which command is used in the Salesforce CLI to retrieve metadata from an org to a local project?

Easy
14

Refer to the exhibit. A developer encounters this error message while deploying an updated trigger to a production environment. What is the most effective approach to diagnose and resolve this deployment failure?

Hard
15

Which TWO statements are true regarding the use of 'System.debug()' in a production environment?

Medium
16

A developer must write Apex tests that reliably cover a Queueable class which performs a callout and then enqueues a second Queueable job. The tests must not make real external callouts. (Choose two.)

Hard
17

A developer is troubleshooting a production issue where a trigger occasionally exceeds CPU time limits. The developer wants to capture detailed debug logs for a specific user without slowing down the entire org, and then analyze the log to identify the slowest operations. Which combination of Salesforce tools should the developer use?

Hard
18

A developer is creating a custom exception to handle business logic errors. What is the correct way to declare this exception so it can be caught specifically in a try-catch block?

Easy
19

A developer needs to debug an Apex trigger that intermittently fails in production with a 'UNABLE_TO_LOCK_ROW' error when multiple users update related records. Which technique should the developer use to capture the detailed execution context and identify the conflicting transaction?

Medium
20

A developer is writing an Apex test class for a service that must be resilient against partial failures. The service calls a REST endpoint using a callout and, when the callout succeeds, performs a DML update on a set of Account records. The developer wants the test to simulate the HTTP response without hitting the real external system. Which approach should the developer use?

Medium
21

What is the best way to test asynchronous Apex (Future methods, Queueable) to ensure the logic within the background job actually executes?

Medium
22

Refer to the exhibit. A developer encounters a 'Maximum stack depth reached' error. What is the most likely cause of this recursive error?

Hard
23

A developer is deploying a new Apex class to production using a change set. The class contains a method that performs a callout to an external web service. During deployment, the developer receives an error: 'Callout not allowed from a test method.' Which action should the developer take to resolve this error while ensuring the test method still validates the callout logic?

Hard
24

A developer is writing a test class for a service that makes callouts to an external web service. The test method needs to simulate the callout response without making an actual HTTP request. (Choose two.)

Medium
25

A developer is writing an Apex class that needs to handle high volumes of data. Which pattern should they follow to avoid hitting Governor Limits?

Medium
26

A developer is preparing to deploy a change set from a sandbox to production. The change set includes a new custom object, its fields, a Visualforce page, and an Apex controller. After uploading the change set, the developer notices that the custom object and fields are missing from the change set components. What is the most likely reason?

Medium
27

A developer is writing an Apex test class for a service that calls an external REST endpoint via a callout. The test must verify the parsing logic without hitting the external system, and it must also assert that the service throws a custom exception when the endpoint returns a 500 status. Which combination of techniques is required?

Medium
28

During a deployment, a developer notices that existing Apex tests are failing, even though the new code changes are unrelated to the failing tests. What is the most likely cause?

Medium
29

A developer is writing a test class that requires a user with a specific profile. How should the developer handle the user creation process?

Medium
30

Refer to the exhibit. A developer encounters this error during a unit test. What is the most likely cause, and how should it be resolved?

Hard
31

A developer is writing an Apex test class for a controller that uses a Visualforce page with a standard controller. The test must cover pagination logic that relies on the StandardSetController. Which TWO actions should the developer take to ensure the test is reliable and covers the pagination behavior? (Choose two.)

Hard
32

A developer is troubleshooting an Apex class that intermittently throws a System.LimitException during integration tests. The developer needs to see the exact sequence of method calls and the values of variables at each step without modifying the class. Which Salesforce feature should the developer use?

Medium
33

A developer is preparing a deployment of a new Apex class and its test class to production. The test class uses @TestSetup to insert 200 Account records, and each of six test methods queries all 200 Accounts. The deployment fails during validation with a CPU timeout error. Which change most directly addresses the timeout without reducing coverage?

Hard
34

A developer needs to give a CI service account the ability to run the Apex test suite in a production org without interactive login, and the pipeline must not store a user's personal password. Which authentication approach should the developer configure?

Easy
35

A developer wants to log information to the Debug Log for a specific class only, without cluttering the logs for the entire organization. What is the most efficient way to achieve this?

Easy
36

Refer to the exhibit. A developer encounters this policy during a deployment attempt via the CI/CD pipeline. What does this indicate about the deployment process?

Hard
37

A developer is preparing to deploy a complex change set from a sandbox to production. The change set includes Apex classes, Visualforce pages, and a new custom object. The developer runs all tests in the sandbox and achieves 100% coverage, but the deployment to production fails with the error: 'Your organization's code coverage is 68%. You need at least 75% coverage to complete this deployment.' What is the most likely cause of this discrepancy?

Hard
38

A developer is writing an Apex test class for a service that calls an external REST API using a Named Credential. The test must not make real callouts, and the developer wants to verify that the correct endpoint and body are sent. Which approach should the developer use?

Medium
39

Which of the following is an advantage of using a 'Source-Driven' development model over an 'Org-Centric' model?

Medium
40

A developer wants to inspect private variable states and trace execution paths of a complex trigger framework during a sandbox debugging session. Which tool should the developer use to capture this diagnostic information?

Easy
41

A developer is preparing for a deployment using Salesforce DX. Which TWO practices are recommended to ensure successful and repeatable deployments?

Medium
42

A developer is debugging why a trigger fires twice for a single record save in a sandbox. The trigger is defined on Account with `before insert, after insert` and the class uses a static Boolean guard variable to prevent recursion. Logs show two separate transactions. Which explanation best fits this behavior?

Hard
43

A developer deploys metadata to a production org using the Salesforce CLI. The deployment succeeds, but a post-deployment validation script that relies on a newly created custom setting record fails because the record is missing. The developer confirms the custom setting metadata was included in the package. What is the most likely explanation?

Hard
44

A developer is attempting to debug a failed deployment in a sandbox. The error message is cryptic, and the debug logs are not capturing the expected execution flow. What should the developer do first?

Medium
45

A developer needs to verify that an asynchronous Apex process (Future method) executes correctly in a test environment. Which approach is best suited to ensure the test waits for the asynchronous execution to finish before asserting the results?

Hard
46

An enterprise development team uses Salesforce DX scratch orgs for feature development. A developer needs to ensure that unit tests execute automatically every time code is committed to the version control system. Which integration approach achieves this requirement?

Medium
47

A developer needs to deploy a complex Apex class and its corresponding test class to production. The org's unit test coverage is currently 74%. Which statement accurately describes the deployment requirements?

Medium
48

An integration test in a sandbox must verify that a callout to an external pricing service returns a parsed response. The test class currently attempts the real callout and fails with a 'Methods defined as TestMethod do not support Web service callouts' error. Which change should the developer make?

Easy
49

Refer to the exhibit. A deployment is failing with this error. What is the most likely cause?

Hard
50

A developer is writing a test class for an Apex trigger that performs a callout. The developer uses a mock class implementing HttpCalloutMock. What happens if the developer fails to implement the mock interface correctly?

Medium
51

Refer to the exhibit. A developer attempts a deployment using Salesforce CLI. The deployment fails with the circular dependency error shown. What is the root cause of this failure?

Hard
52

A developer maintains a managed package and must release a new version. During packaging, the developer needs to ensure that a specific Apex class is accessible to subscriber orgs but that its implementation details remain hidden. Which packaging construct should the developer use?

Hard
53

A developer needs to write a unit test for an asynchronous future method that updates account records. How should the developer structure the test to ensure the asynchronous code executes and validates correctly?

Medium
54

A developer is writing a test class for a service that makes a callout to an external REST API. The test must not perform a real callout, and the developer needs to verify that the service correctly handles both a successful response and an error response. Which approach should the developer use?

Medium
55

Refer to the exhibit. A developer wants to enable log filtering for a specific package. Where should this configuration be managed?

Medium
56

A developer wants to ensure that their Apex code is tested against a specific set of data that is consistent across all sandbox environments. What is the best way to achieve this?

Easy
57

A developer is refactoring a large legacy trigger. They want to ensure performance does not degrade while maintaining test coverage. Which TWO practices should be followed to ensure high-quality, performant testing?

Hard
58

A developer needs to run a single Apex test method named testBulkInsert in a class named AccountServiceTest against a sandbox org and view the results from the command line. Which Salesforce CLI command should the developer use?

Easy
59

Refer to the exhibit. A developer is deploying code using the Salesforce CLI. What is the most likely reason for this failure?

Hard

Frequently asked questions

What does the Testing, Debugging, and Deployment domain cover on the SF-PD2 exam?
Be able to write Apex tests that isolate data, create users with System.runAs, and verify asynchronous logic by wrapping it in Test.startTest and Test.stopTest. For deployment, use Salesforce DX with version control and scratch orgs so releases are repeatable and validated before production.
How many questions are in this domain?
This page lists all 59 Testing, Debugging, and Deployment questions in the SF-PD2 question bank. The actual exam draws from this domain proportionally to its weighting in the official exam blueprint.
What is the best way to practise this domain?
Start with a short focused session (10 questions) to identify gaps, then work through explanations. Repeat with a longer session once the weak areas feel solid.
Can I practise only Testing, Debugging, and Deployment questions?
Yes — the session launcher on this page filters questions to this domain only. Choose any session length for inline explanations and scoring.
salesforce-platform-developer-ii SALESFORCE-PLATFORM-DEVELOPER-II testing debugging deployment Practice Questions