Got the System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out
But already completed the DML operations before calling http callout.
global Response createVFPage(
.... params) {
// DML operations
// create VF page
String markupContent = configureDefaultSections(navigationJsonName, pageTitle);
Map<String, String> pageCreationReq = new Map<String, String>{
.......
};
String httpReqContent = JSON.serialize(pageCreationReq);
res = sendVFPageCreationRequest(httpReqContent);
if ((res.getStatusCode() == 200) || (res.getStatusCode() == 201)) {
return true;
} else {
return JSON.serialize(res.getBody());
}
}
private HTTPResponse sendVFPageCreationRequest(String pageCreationReq) {
String url = salesforceHost + '/services/data/v29.0/sobjects/ApexPage';
HttpRequest req = new HttpRequest();
req.setMethod('POST');
req.setEndpoint(url);
req.setHeader('Content-type', 'application/json');
req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionId());
req.setBody(pageCreationReq);
Http http = new Http();
return http.send(req);
}