Newer Version Available

This content describes an older version of this product. View Latest

Using the Timeout Parameter with Asynchronous Calls

If necessary, you can specify a maximum timeout for an asynchronous call with AJAX Toolkit.
If an asynchronous call does not complete in an appropriate amount of time, you can end the call. To do this, specify the timeout parameter in the callback section of any asynchronous call:
1var account = new sforce.SObject("Account");
2account.Name = "my new account";
3
4sforce.connection.create([account], {onSuccess: print, onFailure: printerr, timeout: 100});

Values for this parameter are in milliseconds, and valid values are integers beginning with 1.

If the call is successful within the time specified by the callout, no additional actions are taken. If the call is not successful, the onFailure action is performed.

Use this parameter with caution. Because the timeout is performed on the client side, it is possible that the call may complete on the server but the timeout is still triggered. For example, you might issue a create call to create 100 new accounts, and any number of them, 1 or 100, might be created just before the timeout is triggered; your onFailure action would still occur, but the accounts would have been created.

Warning