Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
Visualforce Remote Objects Callback Functions
Callback functions are a standard technique in JavaScript for handling events and asynchronous operations. Remote Objects uses this pattern to handle the response of its asynchronous operations. When you invoke a Remote Objects operation, you provide the parameters of the operation and, optionally, a callback function. Your JavaScript code continues uninterrupted after you invoke the operation. When the remote operation is completed and results are returned, your callback function is invoked and receives the results of the operation.
1function callback(Error error, Array results, Object event) { // ... }| Name | Type | Description |
|---|---|---|
| error | JavaScript Error object | A standard JavaScript Error object. If the operation succeeded, error is null. Use error.message to retrieve the reason for a failure. |
| results | JavaScript array | An array that contains the results of the operation. If the operation was a retrieve(), the results are instances of the appropriate Remote Objects. Otherwise, the array contains strings that represent the Ids of affected records. |
| event | JavaScript object | A JavaScript object that provides the details of the JavaScript remoting event transporting the Remote Objects operation. |
Example
1function getAllContacts() {
2 $j.mobile.showPageLoadingMsg();
3
4 var c = new RemoteObjectModel.Contact();
5 c.retrieve({ limit: 100 }, function (err, records) {
6 // Handle errors
7 if (err) {
8 displayError(err);
9 } else {
10 // Add the results to the page
11 var list = $j(Config.Selectors.list).empty();
12 $j.each(records, function() {
13 var newLink = $j('<a>'+this.get('FirstName')+' '+this.get('LastName')+'</a>');
14 newLink.appendTo(list).wrap('<li></li>');
15 });
16
17 $j.mobile.hidePageLoadingMsg();
18 list.listview('refresh');
19 }
20 });
21}