Happy Business Starts Here

Salesforce error: "The callout was unsuccessful after 4 attempts: You have uncommitted work pending"

Highlighted
Zuora Alumni

Salesforce error: "The callout was unsuccessful after 4 attempts: You have uncommitted work pending"

Question:

Why do I get the Salesforce error: "The callout was unsuccessful after 4 attempts: You have uncommitted work pending"?



If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √

1 REPLY 1
Zuora Alumni

Re: Salesforce error: "The callout was unsuccessful after 4 attempts: You have uncommitted work

Answer

 

In Salesforce, a callout can not be made when there is uncommitted data pending (not committed to the database).

 

If the callout can occur before Database insert/update, then do the callout prior to those data operations.

 

Otherwise, ensure the callout will be run in a separate execution context.

 

This is a general issue all Salesforce developers need to be aware of and address. This is not specific to the Zuora APIs.

 

This article covers the case when this error is encountered in Custom Code, if you are experiencing this error with the OOTB Zuora Quotes, then please contact support for further assistance.

 

 

Options

 

UI Flow

 

If the flow is governed by UI actions (e.g. - clicking a button) saving the data first, then separating the callout to be triggered by a different button will effectively separate the callout into a separate execution scope

 

APEX

  

Create a separate function, or helper class with a function, annotated with a future annotation.

 

public class FutureCalloutHelper {

@future(callout=true)
public static void doCallout(parameters){

//do callout

}

}

 

Visualforce Page

 

Separate the save and callout into different functions and trigger the callout with the oncomplete event

 

@VisualforcePage

 <apex:actionFunction name="doCallout" action="{!doCallout}"></apex:actionFunction>
 <apex:commandButton value="Save" action="{!save}" oncomplete="doCallout()" />
 
@Controller
 
public PageReference save() {
  //save or update data
}
 
public PageReference doCallout(){
  //do the callout and return new page id
}

 

 

References

 

 



If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √