2

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?

6
  • Can you try listingPage.setRedirect(true) to disable server side redirect? Mar 28, 2014 at 12:48
  • 1
    Also is your listingPage using the same controller? Mar 28, 2014 at 12:49
  • I would suggest it is synchronous, because after inserting an object you immediately have access to the Id field, which is updated in the object within the scope of the calling method, by the Insert, so it must have completed before execution continues. I would imagine there is some other quirk affecting your expected behaviour. Maybe some more code/information will help us debug with you! Mar 28, 2014 at 13:04
  • The listingPage uses a different controller. Will try setRedirect() -- but since the issue does not happen consistently, it will be hard to tell if this solved the problem. Mar 28, 2014 at 13:15
  • Is anotherFutureMethod (=async?) doing anything on the object that might impact whether or not it shows up in your following query?
    – Keith C
    Mar 28, 2014 at 15:49

0

You must log in to answer this question.

Browse other questions tagged .