Skip to content

Updating Single Object

Method

Future<Map> Backendless.data.of("TABLE-NAME").save(Map entity);
Future<E> Backendless.data.withClass<E>().save(E entity);

where:

Argument                Description
TABLE-NAME Name of the table where the object represented by Map will be updated. There must be objectId property in the map. The value of the property identifies the object which will be updated.
E Dart class of the data object to update.
entity Dart object to persist, must be of type E or Map (depending on the method used).

Return Value

The updated object of type E or Map.

Example

void updateContact() {
  // create new contact object first. Then we will update it.
  Map contact = {
    "name": "Jack Daniels",
    "age": 147,
    "phone": "777-777-777",
    "title": "Favorites",
  };

  Backendless.data.of("Contact").save(contact).then((savedContact) {
    savedContact["title"] = "Most favorite";
    savedContact["phone"] = "666-666-666";
    Backendless.data.of("Contact").save(savedContact).then((response) {
      // Contact object has been updated
    });
  });
}
Consider the following class:
import 'package:backendless_sdk/backendless_sdk.dart';

@reflector
class Contact {
  String objectId;
  String name;
  int age;
  String phone;
  String title;
}
The following code saves a new instance of the Contact class and subsequently updates it:
void updateContact() {
  Contact contact = Contact()
    ..name = "Jack Daniels"
    ..age = 147
    ..phone = "777-777-777"
    ..title = "Favorites";

  Backendless.data.withClass<Contact>().save(contact).then((savedContact) {
    // now update the saved object
    savedContact.title = "Most favorite";
    savedContact.phone = "666-666-666";
    Backendless.data.withClass<Contact>().save(savedContact).then((response) {
      // Contact instance has been updated
    });
  });
}