Salesforce-Platform-Developer-II Practice Test

Salesforce Spring 25 Release
202 Questions

A developer has working business logic code, but sees the following error in the test class:
You have uncommitted work pending. Please commit or rollback before calling out.
What is a possible solution?

A. Call support for help with the target endpoint, as It is likely an external code error

B. Use mast. T=RunningTes={} before making the callout to bypass it in test execution,

C. Set seeAllData to true the top of the test class, since the code does not fall in practice.

D. Rewrite the business logic and test classes with @Testvisible set on the callout.

B.   Use mast. T=RunningTes={} before making the callout to bypass it in test execution,

Explanation:

✅ B. Use mast. T=RunningTes={} before making the callout to bypass it in test execution
This is the correct solution. In test classes, Salesforce does not allow real callouts. To simulate a callout, developers must use the Test.setMock() method, which replaces the actual HTTP callout with a mocked response. This helps to avoid the “uncommitted work pending” error, especially when DML operations happen before the callout. The mock class must implement HttpCalloutMock to return a fake HttpResponse. This is standard best practice for writing unit tests that include callouts.
🔗 Reference: Salesforce Docs – Test.setMock() and HTTP Callouts

❌ A. Call support for help with the target endpoint, as It is likely an external code error
This is not a valid solution. The error message “You have uncommitted work pending” is generated by the Salesforce platform, not the external endpoint. It happens because a DML operation (like an insert or update) was performed before a callout, which violates Salesforce’s internal execution rules. The issue is not external, so contacting Salesforce or an external API provider won’t help. You must resolve this in your Apex logic by either reordering the operations or mocking the callout in a test environment.
🔗 Reference: Salesforce Developer Forums – Uncommitted Work Pending Error

❌ C. Set seeAllData to true the top of the test class, since the code does not fall in practice.
This is an incorrect workaround. The seeAllData=true annotation in test classes allows access to the org’s real data but has no relation to callouts or DML operations. Enabling this flag does not suppress or solve the uncommitted work issue. It's also discouraged because it makes tests unreliable and dependent on real data. The proper fix is to use Test.setMock() to simulate the callout and avoid the DML-before-callout violation altogether.
🔗 Reference: Salesforce Docs – Test Classes and seeAllData

❌ D. Rewrite the business logic and test classes with @Testvisible set on the callout.
This is also not a valid solution. The @TestVisible annotation is used to expose private members or methods in Apex classes to test methods, allowing you to test logic that is normally inaccessible. However, it does nothing to fix callout-related errors or execution order issues like “uncommitted work pending.” Adding @TestVisible to a method does not bypass the restriction of DML before callout. You still need to use mocking techniques to ensure the callout doesn’t actually execute during testing.
🔗 Reference: Salesforce Docs – @TestVisible Annotation

✅ Final Answer:
B. Use mast. T=RunningTes={} before making the callout to bypass it in test execution

Salesforce-Platform-Developer-II Practice-Test - Home Previous
Page 13 out of 202 Pages