Salesforce
PDII · Question #215
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…
The correct answer is C. Use test.IsRunningTest() before making the callout to bypass it in test execution. See the full explanation below for the reasoning.
Question
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?
Options
- ARewrite the business logic and test classes with @TestVisible set on the callout
- BSet seeAllData to "true" at the top of the test class, since the code does not fail in practice
- CUse test.IsRunningTest() before making the callout to bypass it in test execution
- DCall support for help with the target endpoint, as it is likely an external code error
How the community answered
(44 responses)- A5% (2)
- B14% (6)
- C75% (33)
- D7% (3)
Community Discussion
No community discussion yet for this question.