Last active
February 2, 2024 03:52
-
-
Save msrivastav13/67a369ae1508f6160ba47248cb7abc52 to your computer and use it in GitHub Desktop.
Example to show the callout after DML rollback in Apex with new Database.releaseSavepoint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This class works if your class -meta.xml is of 60.0 version | |
public with sharing class SavePointReleaseCalloutExample { | |
public void basicAuthCallout() { | |
// Do a DML before callout | |
Savepoint sp = Database.setSavepoint(); | |
Account acc = new Account(); | |
acc.Name = 'Test'; | |
insert acc; | |
Database.rollback(sp); | |
Database.releaseSavepoint(sp); | |
HttpRequest request = new HttpRequest(); | |
request.setEndpoint('https://dog.ceo/api/breeds/image/random'); // Set the endpoint URL | |
request.setMethod('GET'); // Set the HTTP POST method | |
// Set the request headers | |
request.setHeader('Content-Type', 'application/json'); | |
request.setHeader('Accept', 'application/json'); | |
// Send the request | |
Http http = new Http(); | |
HttpResponse response = http.send(request); | |
// Process the response | |
if (response.getStatusCode() == 200) { | |
String responseBody = response.getBody(); | |
System.debug(responseBody); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment