---
schema_version: "1"
id: 269ee4879e42b4e892ff964903af35b6d6922a048b684674320b8c226e9cbefc
title: Visualforce Remote Objects Callback Functions
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/platform/salesforce-pages-developers-guide/guides/pages/javascript/pages-remote-objects-callback-functions.md
canonical_url: https://developer.salesforce.com/docs/platform/salesforce-pages-developers-guide/guide/pages-remote-objects-callback-functions.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 6f1b19974f9639df99f6453b36ba69feb88ff5aec014efe6d6981c3348a50bc2
products:
  - Visualforce Developer Guide
  - Platform Developer Content
---

# Visualforce Remote Objects Callback Functions

Remote Objects sends all requests to the Salesforce service asynchronously. Your code handles responses to Remote Objects operations in a callback function that you provide. Callback functions handle updating the page with the results of the operation and errors that are returned.

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.

Remote Objects callback functions can be written to receive up to three arguments.

```javascript
function callback(Error error, Array results, Object event) { // ... }
```

|Name|Type|Description|
|----|----|-----------|
|`error`|JavaScript [Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/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 `Id`s of affected records.|
|`event`|JavaScript object|A JavaScript object that provides the details of the JavaScript remoting event transporting the Remote Objects operation.|

Most callback functions check for errors and then take an action with the results. The `event` object is typically used only in debugging and sophisticated error management.


## Example

Here’s a straightforward callback function, which handles the results of a `retrieve()` operation.

```javascript
function getAllContacts() {
    $j.mobile.showPageLoadingMsg();
    
    var c = new RemoteObjectModel.Contact();
    c.retrieve({ limit: 100 }, function (err, records) { 
        // Handle errors
        if (err) { 
            displayError(err); 
        } else {
            // Add the results to the page
            var list = $j(Config.Selectors.list).empty();
            $j.each(records, function() {
                var newLink = $j('<a>'+this.get('FirstName')+' '+this.get('LastName')+'</a>');
                newLink.appendTo(list).wrap('<li></li>');
            });
            
            $j.mobile.hidePageLoadingMsg();
            list.listview('refresh');
        }
    });
}

```

In this sample, `getAllContacts()` calls `retrieve()` and passes an anonymous function as the callback. The callback function checks for errors and then uses jQuery to iterate through the array of result records, adding them to the page. Some details are omitted to focus on the callback structure. See [An Example of Using Visualforce Remote Objects with jQuery Mobile](https://developer.salesforce.com/docs/platform/salesforce-pages-developers-guide/guide/pages-remote-objects-example-extended.md) for the complete page source code.

**See Also**  


-   [An Example of Using Visualforce Remote Objects with jQuery Mobile](https://developer.salesforce.com/docs/platform/salesforce-pages-developers-guide/guide/pages-remote-objects-example-extended.md)

