Savepoint sp = Database.setSavepoint();
insert new Campaign(Name='test');

HttpRequest req = new HttpRequest();
Http http = new Http();
HttpResponse res = 

If you paste the above code into an anonymous block and execute, you will get the following error message:

System.CalloutException: You ahve uncommitted work pending. Please commit or rollback before calling out

However, as you can see, I am rolling back on the third line there. Am I missing something?

1 Answer 1


You're not able to do that, you can't do an HTTP callout either after a DML operation or a setting of a Savepoint. Documentation here mentions DML, but not the Savepoint that I can see, but that is the case.

  • 3
    Using SavePoint does cost a DML operation, however (of the 150/transaction variety). Transaction Control explains this: "Each savepoint you set counts against the governor limit for DML statements."
    – sfdcfox
    Mar 30, 2015 at 19:54
  • 3
    The error message says "Please commit or rollback before calling out." How, then, am I supposed to rollback to do my callout? Apr 1, 2015 at 14:09
  • Why are you rolling back anyway, what would be the point of that? I think in light of what limitations there are around this, you'll need to refactor your code. What is it you're trying to achieve? Apr 1, 2015 at 14:11
  • I'm rolling back because of an error condition in a future method, which is invoked by a REST service I've exposed. Client has an endpoint that I can hit with an error message, so the intention is to roll back and then call out to notify of the error. Apr 7, 2015 at 14:05
  • Yeah thats going to be tricky without some refactoring. Here's an interesting post that has some creative solutions salesforce.stackexchange.com/questions/54931/… Apr 7, 2015 at 15:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.