Advertisement
martyychang

AccountUtil: cannot make callout after Savepoint

Feb 20th, 2014
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.76 KB | None | 0 0
  1. /*
  2.  * @see http://salesforce.stackexchange.com/questions/27992/salesforce-unittest-exception-message-you-cannot-make-callout-after-creating-a
  3.  */
  4. public class AccountUtil {
  5.     public static void createAccount() {
  6.         System.Savepoint savepoint = Database.setSavepoint();
  7.  
  8.         try {
  9.             insert new Account(Name = '#deleteafter ' + DateTime.now());
  10.         }
  11.         catch (System.DMLException caught) {
  12.             Database.rollback(savepoint);
  13.         }
  14.     }
  15.  
  16.     public static String makeCallout() {
  17.         HttpRequest request = new HttpRequest();
  18.         request.setEndpoint('http://www.dilbert.com');
  19.         request.setMethod('GET');
  20.  
  21.         HttpResponse response = new Http().send(request);
  22.  
  23.         return response.getBody();
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement