You need to sign in to do that
Don't have an account?
System.CalloutException: You have uncommitted work pending
I am making a google api call and I am getting the above exception. There is no DB call made before or after ....
public PageReference save() {
List<Event> passUpdateEvt = new List<Event>();
for(Event crud : event){
system.debug('selectedGoogle'+ crud.selectedGoogle__c);
if (crud.selectedGoogle__c)
{
passUpdateEvt.add(new Event(subject = crud.Subject,
description = crud.Description,
startdatetime = crud.StartDateTime,
enddatetime = crud.enddatetime,
location = crud.location));
}
// this makes a call to the google api error is raised with the
//System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out
//Class.GoogleService.getFeedMethod: line 184, column 15 Class.GoogleService.makePostRequest: line 84, column 3 //Class.CalendarService.updateEventBatch: line 227, column 9 Class.GooglePullController.save: line 475, column 13 //External entry point
service.updateEventBatch(cal, passUpdateEvt);
}
PageReference pgref = new PageReference('/apex/CustomTabTest');
pgref.setRedirect(true);
return null;
}
You will need to separate out the callout and the redirection. Convert the callout things to a future method and that will solve your problem.