---
schema_version: "1"
id: 06af1a16dcfc92e661b27914e39660544d5dbf446df578f1ae618f017ca798cd
title: Updating Records with Remote Objects
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-using-update.md
canonical_url: https://developer.salesforce.com/docs/platform/salesforce-pages-developers-guide/guide/pages-remote-objects-using-update.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 4d485dd16cfc4a144319e3c4ab668fcc1b635fcb2b4c70c690868d5c656c7c85
products:
  - Visualforce Developer Guide
  - Platform Developer Content
---

# Updating Records with Remote Objects

Update records by calling `update()` on a Remote Objects model instance.

`update()` accepts three arguments, all optional, and can update one or many records at the same time, depending on the arguments that you provide.

```javascript
RemoteObjectModel.update([record_ids], {field_values}, callback_function)
```

`record_ids` is an array of strings, where the strings are the `Id`s of records to be updated. If this parameter is omitted, the `Id` that is set on the Remote Object instance is used. The simplest way to update a record is to call `update()` on itself.

```javascript
ctDetails = {FirstName: "Marc", LastName: "Benioff"};
ct = new RemoteObjectModel.Contact(ctDetails);
ct.create();

// Later, in response to a page event...
ct.set('Phone', '555-1212');
ct.update();
```

More often, you might need to update a record in response to a form submission. Updating the record can be as simple as reading some form values, including the record’s `Id`, and passing the values to `update()`. For example:

```javascript
var record = new RemoteObjectModel.Contact();
record.update($j('#contactId').val(),
{
    FirstName: $j('#fName').val(),
    LastName: $j('#lName').val(),
    Phone: $j('#phone').val(),
    Notes: $j('#notes').val() 
});
```

Robust code includes a callback to handle errors. The following code accomplishes the same as the previous sample, altered to use an event handler and a callback function.

```javascript
// Handle the Save button
function updateContact(e){
    e.preventDefault();

    var record = new RemoteObjectModel.Contact({
        Id: $jQuery('#contactId').val(),
        FirstName: $jQuery('#fName').val(),
        LastName: $jQuery('#lName').val(),
        Phone: $jQuery('#phone').val(),
        Notes: $jQuery('#notes').val() 
    });
    record.update(updateCallback);
}

// Callback to handle DML Remote Objects calls
function updateCallback(err, ids){
    if (err) { 
        displayError(err); 
    } else {
        // Reload the contacts with current list
        getAllContacts();
        $jQuery.mobile.changePage('#listpage', {changeHash: true});
    }
}

```

You can update many records at the same time, as long as the update to be performed is uniform, that is, the same for every record. For example, you might need to update a collection of checked items from a list, to change a status field to “Archived” or a current timestamp. To update records in one request, pass an array of `Id`s to `update()`. The fields to be updated can be set as part of the Remote Object model itself, but it’s safer to pass them directly to `update()`, like this:

```javascript
var ct = new RemoteObjectModel.Contact();
ct.update(
    ['003xxxxxxxxxxxxxxx', '003xxxxxxxxxxxxxxx'], 
    { FirstName: "George", LastName: "Foreman" },
    function(err, ids) {
        if (err) { 
            displayError(err); 
        } else {
            // Reload the contacts with current list
            getAllContacts();
            $jQuery('#status').html(ids.length + ' record(s) updated.');
            $jQuery.mobile.changePage('#listpage', {changeHash: true});
        }
});
```

**note:** When you update multiple records this way, all of the records are updated in the same server-side transaction.

**See Also**  


-   [Visualforce Remote Objects Callback Functions](https://developer.salesforce.com/docs/platform/salesforce-pages-developers-guide/guide/pages-remote-objects-callback-functions.md)

