function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Mahesh NirmalMahesh Nirmal 

Getting an A callout was unsuccessful error for Big Object

Hi,
I am having an Big Object on which I am quering the record from it and inserting the record to Account object and once the data is inserted in account object I am deleting the data from Big Object.

During this process for DML I am getting the below Error-

EXCEPTION_THROWN [95]|System.UnexpectedException: A callout was unsuccessful because of pending uncommitted work related to a process, flow, or Apex operation. Commit or roll back the work, and then try again.

Please assist on this.
Thanks

ShivankurShivankur (Salesforce Developers) 
Hi Mahesh,

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.

Options to solve this:
  • 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
}

Few more references:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_future.htm
https://help.salesforce.com/articleView?id=000328873&type=1&mode=1

Hope above information helps. Please mark as Best Answer so that it can help others in future.

​​​​​​​Thanks.
Mahesh NirmalMahesh Nirmal

Hi Shivankur,

Thank you for your Reply.

We are trying that on big object and we are not having any callout in that.

ShivankurShivankur (Salesforce Developers) 
Hi Mahesh,

You might need to separate the transaction mentioned above into two separate transaction, where you can query the data from Big object and insert the account records.

Once the account records is successfully created and first transaction is ended/finished then only you should start next transaction to query on Big object for the same data and delete it. This could be the probable root cause for this error since second operation is not being completed when there is pending work to be commited.

Hope above information helps. Please mark as Best Answer so that it can help others in future.

Thanks.
Ramon Mora 4Ramon Mora 4
Hi Shivankur,

I was having the same problem today and your second answer solved it, I didn't know queries on Big Objects behaved like asynchronous operations.

Thanks.