You need to sign in to do that
Don't have an account?
pcave_jacksonriver
Gracefully exit from batch apex
Is there a way to exit out of a batch process early? I'm working on a batch process that will be calling an external webservice, but since you're only allowed 1 callout, the session may expire during processing and I won't be able to reconnect. So I'll want to exit at that point.
Is this possible?
You could set the timeout explicitly in Apex Code to a reasonable value you would be prepared to wait for a response, as illustrated in http://wiki.developerforce.com/page/Apex_Web_Services_and_Callouts
You could have response = webservice.callout //psuedo code
You could then make the execution of any further code dependant on the response - (you will need to make your Batch Apex Class Stateful I'm guessing to maintain state and ascertain whether a response was received)
if(response)
{
//further processing
}
So all further executions of execute() would merely return empty.
I'd also be inclined to try and abort the current Batch Apex job if an expected response is not received from the callout, using a System.abortJob()
http://boards.developerforce.com/t5/Apex-Code-Development/Batch-Apex-problems/td-p/242867