You need to sign in to do that
Don't have an account?
chris_centra
WebServiceMock from batch process - uncommitted work pending exception
Hello. I started using the the WebServiceMock interface shortly after it came out, but there was an issue where it would throw the "uncommitted work pending" exception. this is found elsewhere in the forums. i recently had the need to use WebServiceMock again - and i found that the issue was resolved (https://developer.salesforce.com/forums?id=906F0000000927CIAQ) - so i tried it. but i'm still having the same issue - sometimes. My callout happens either as the result of a trigger execution or a batch process. With the trigger, it works perfectly - no "uncommited work pending" exception. however when i call it from my batch process, i'm still seeing the same issue.
a few notes here. i've confirmed that all of my code is v29. in my batch process, i disable the trigger - so it's not like the callout is firing multiple times. i've implemented my test method per the instructions noted in the linkd above (first setup data, then calling Test.startTest, then setMock, then do callout, then call stopTest. i've checked the debug log thoroughly - there is no dml between my Test.startTest and the callout. so this is a bit mysterious to me. is anyone seeing a similar issue?
thanks
chris
a few notes here. i've confirmed that all of my code is v29. in my batch process, i disable the trigger - so it's not like the callout is firing multiple times. i've implemented my test method per the instructions noted in the linkd above (first setup data, then calling Test.startTest, then setMock, then do callout, then call stopTest. i've checked the debug log thoroughly - there is no dml between my Test.startTest and the callout. so this is a bit mysterious to me. is anyone seeing a similar issue?
thanks
chris
Please refer following help document addressing this issue:
https://help.salesforce.com/apex/HTViewSolution?urlname=You-have-uncommitted-work-pending-Please-commit-or-rollback-before-calling-out-1327108312571&language=en_US
thanks
chris
You have to split the execution of the callout into another class and then avoid execution of that class if a test is running.
Then have another test class to get coverage for the class doing the callout.
We can use isRunningTest() method in batch class to avoid the execution of newly created class(for HTTP callout) while running a test.
maybe i'm just not understanding this response, but i don't think this gets to the root of the issue. i don't want to completely avoid execution of the callout - instead i want it to use the WebServiceMock functionality as it is intended. it's frustrating. it seems like WebServiceMock comes so close to giving me exactly what i need, but it has a flaw which renders it useless in this scenario. please let me know if their response means something to you...
thanks
chris
Sometimes salesforce can be a real disapointment. They should at least update their documenation to explain this...