Find your content:

Search form

You are here

sObject insert execution not synchronous

 
Share

I have a custom object and a controller action that creates a new record of this type. The action then returns a page where the list of objects are displayed.

save() {
    ... 
    insert myObject;

    if (myObject.id != null) {
      anotherFutureMethod(myObject.id); 
      return listingPage; 
    } else {
      return null;
    }
}
@future static void createExternalUser(String objId) { 
     ....
     newUser = new User(...);
     insert u;
}

The listingPage.page uses javascript to invoke a remote action that queries the database:

<apex:define name="scripts">
  <script type="text/javascript" charset="UTF-8">
  var $j = jQuery.noConflict();
  Visualforce.remoting.timeout = 120000; 

   $j(document).ready( function () {
      ...
      Visualforce.remoting.Manager.invokeAction('{!$RemoteAction.DataTables.getMyObjects_json}',aoData, handleResult);

    });
  </script>
</apex:define>

We used this listing pattern for other object listings and never see any problem -- that why I think the issue is on the data creation side.

The issue is that the new myObject record does not always not shown in the listing page right action return. If it wasn't shown, a page reload will include the new record. It seemed that the sObject insert may not always happen before the action return. The action is NOT marked asynchronous -- can someone explain the possible cause of this behavior?


Attribution to: blu le temps
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/31169

My Block Status

My Block Content