3

Im getting CalloutException.You have uncommitted work pending.

Here's my VF Page.

<apex:commandbutton> SAVE </apex:commandbutton> 

<apex:pageBLock>
<apex:column>
  <apex:inputcheckbox />
<apex:column>
<apex:column>
  //Webserive is called here to display image. I pass the ID of this record and get image.
  <apex:image url="{!PhotoMap[item.id]}"></apex:image> 
<apex:column>
<apex:pageBLock>

I select one of the rows..then click Save. On clicking save, I save a child record for each of the selected rows. One of the columns is to display image which will call the imageService.

Scenario: On page load, the images are displayed correctly without any error. The service is called perfectly. Now, when I select one record, save it. The record is getting saved, but the image is gone. And if I refresh now the image is back.

The error says. You have uncommitted work pending. Please commit or rollback before calling out. How to handle this?

Please let me know. Thanks.

  • 1
    We will probably need to see more code than just this, but the reason for the error is because you can't make a callout after trying to save a record. You'll have to re-order your code so that any callouts are performed before attempting to save. – sfdcfox May 21 '14 at 4:29
0

Changing the order in my code worked.

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.