i cannot invoke asynchornous method before Callout,how to resolve this issues?
public class CalloutService {
public void callout_test1() {
CalloutService.doDML();
HttpResponse r = call();
//process ...
}
public void callout_test2() {
BatchUpsert bu = new BatchUpsert();
Database.executeBatch(bu);
HttpResponse r = call();
//process ...
}
public HttpResponse call() {
Http h = new Http();
HttpRequest r = new HttpRequest();
r.setEndpoint('https://ap2.salesforce.com');
r.setMethod('GET');
HttpResponse r2 = h.send(r);
return r2;
}
@future()
public static void doDML() {
//
//Account a = [SELECT Id, Name FROM Account LIMIT 1];
//UPDATE a;
System.debug('----');
}
}
when i use it as follow
CalloutService cs = new CalloutService(); cs.callout_test1();
Or like this:
CalloutService cs = new CalloutService(); cs.callout_test2
Then i got this problem(even my future or batch method has no dml operations):
System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out
pls help me out.