I am experiencing some bizarre behaviour when trying to insert external objects. The following statement results in an error:

Object__x o = new Object__x(Name__c='Test');
Database.SaveResult[] sr = Database.insertAsync(new Object__x[]{o}, new MyCallback());

The error is:

statusCode=ASYNC_OPERATION_LOCATOR, code=null, message=x00upsert-08P0n0000004pHG, fields=[]

However the request goes through if I remove the return value of Database.insertAsync:

Object__x o = new Object__x(Name__c='Test');
Database.insertAsync(new Object__x[]{o}, new MyCallback());

So it seems the return value is causing the problem. But why?


These are not error messages. When you do an external async method, you get the async ID in the message field that you can use later with Database.getAsyncSaveResult(). Here's the relevant information from the documentation:

Return Value

Type: List<Database.SaveResult>

Status results for the insert operation. Each result corresponds to a record processed by this asynchronous operation and is associated with a unique identifier (asyncLocator). The asyncLocator value is included in the errors array of the result. You can retrieve this identifier with Database.getAsyncLocator(). Retrieve the final result with Database.getAsyncSaveResult().

If you want to check the results later, use the asyncSaveId provided as the return value, otherwise if you just want the callback to happen, use the callback parameter.

  • The 08P keyprefix in the message is for a BackgroundOperation. Seems to make sense that it could be used to check for the async operation result once it completes. – Daniel Ballinger Aug 29 '17 at 1:15
  • But with the return value present no callout seems to happen. On top of that the resulting Databse.SaveResult comes back with an explicit error: Database.SaveResult[getErrors=(Database.Error[getFields=();getMessage=x00upsert-08Pg0000000GFwg;getStatusCode=ASYNC_OPERATION_LOCATOR;]);getId=null;isSuccess=false;] – Mossi2 Aug 30 '17 at 18:27
  • @Mossi2 The return value makes no difference; a method returns a value regardless of if you choose to check it. For example, consider this exec anon code: Integer getValue() { System.debug('Called method'); return 5; } Integer i = getValue(); getValue(); You need to check the status of the callback later, independently, and it is the asycLocator that allows you to check it. My guess is that you've decided to abort/rollback because of isSuccess=false; if you roll back, your callback won't happen. – sfdcfox Aug 30 '17 at 18:33
  • @sfdcfox I thought the same; that's why I am calling this bizarre. I ran the 2 statements raw in the Developer Console with nothing else to verify. Also as mentioned in my previous comment the result is coming back explicitly as an error. – Mossi2 Aug 30 '17 at 18:37

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.