11

I have a Remote action call from my Visualforce Page.

Visualforce.remoting.Manager.invokeAction(
           '{!$RemoteAction.PartnerPrimeSubController.calculatePartnerPrimeSub}',
            handlePartnerPrimeSubResult,
            {escape: false}
);

and my controller "PartnerPrimeSubController" looks like this

@RemoteAction
global static List<String> calculatePartnerPrimeSub(){
    //Custom Code
    return finalJSONData;
}

Is it possible to make JSRemoting Asynchronous?

I tried something like this and failed:

@future @RemoteAction
global static List<String> calculatePartnerPrimeSub(){
    //Custom code
}

Use Case behind this requirement:

  1. I am trying to invoke 10 VF Remoting calls after DOM Load Complete in my Visualforce Page. When i checked the network in chrome console, Salesforce tries to
    process 1 VF remoting call at a time.
  2. Salesforce completes 1 remoting call and 9 other VF Remoting call seems to be waiting until first remoting completes.
  3. I am also trying to improve the performance of my page by moving away from Action Function and implementing Lazy loading through VF Remoting.

Any pointers?

4
  • Do you need to make 10 separate Vf Remoting calls? Can't you consolidate some of them? Whats the scenario? Oct 28, 2013 at 21:55
  • Each and every Remoting Call have different SOQL and different Business Logic behind it. My Visualforce page is actually a component and it is used in other pages too.
    – Jag
    Oct 28, 2013 at 21:56
  • It is async, thats why the result is passed to a callback.
    – Phil Rymek
    Oct 28, 2013 at 22:02
  • @phil, This is what i found in Salesforce APEX documentation: "The remote method call executes synchronously, but it doesn’t wait for the response to return. When the response returns, the callback function handles it asynchronously. "
    – Jag
    Oct 28, 2013 at 22:05

1 Answer 1

18

I guess the answer is the SF document itself. Have a look at this link http://www.salesforce.com/us/developer/docs/pages/Content/pages_js_remoting.htm

You can configure your remoting call using these three parameters "buffer","timeout" and "escape". Usually written at the end of a call.

You have to look for the parameter "buffer". As per the docs buffer decides

Whether to group requests executed close to each other in time into a single request. The default is true.

So to make your individual call to the controller you have to set this parameter as "false"

Example

Visualforce.remoting.Manager.invokeAction(
        '{!$RemoteAction.MyController.getAccount}', 
        accountName, 
        function(result, event){

        }, 
        { buffer: false, escape: true, timeout: 30000 }
    );
2
  • 1
    By the way remote action are always async and I guess what you want is to have a individual call.
    – Avidev9
    Oct 28, 2013 at 22:10
  • since by default buffer=true in VF remoting, i was fooled by Chrome Network Console which appeared to be synchronous call. Thanks for clarification.
    – Jag
    Oct 28, 2013 at 22:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .