Skip to content

Deleting Single Object

Method

Future<int> Backendless.data.of("TABLE-NAME").remove({Map entity, String whereClause});
Future<int> Backendless.data.withClass<E>().remove({E entity, String whereClause});

where:

Argument                Description
TABLE-NAME Name of the table where the object represented by Map will be deleted from. There must be objectId property in the map. The value of the property identifies the object which will be deleted.
E Data class of the data object to delete.
entity Data object to delete. Must contain the objectId property which identifies the object in the database.

Return Value

The timestamp when the server-side removed the object from the data store.

Example

void deleteContact() {
  Map contact = {
    "name": "Jack Daniels",
    "age": 147,
    "phone": "777-777-777",
    "title": "Favorites",
  };

  Backendless.data.of("Contact").save(contact).then((savedContact) {
    // now delete the saved object
    Backendless.data.of("Contact").remove(entity: savedContact);
  });
}

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 deleteContact() {
  Contact contact = Contact()
    ..name = "Jack Daniels"
    ..age = 147
    ..phone = "777-777-777"
    ..title = "Favorites";

  Backendless.data.withClass<Contact>().save(contact).then((savedContact) {
    // now delete the saved object
    Backendless.data.withClass<Contact>().remove(entity: savedContact);
  });
}

Codeless Reference

data_service_delete_object

where:

Argument                Description
table name Name of the data table where an object will be deleted from.
object or objectId This parameter expects either a unique identifier(objectId) of the record that must be deleted in the data table, or a data object which must contain the objectId property which identifies the object in the database. String value or number.

This operation does not return a value.

Consider the following records in the employees data table:

data_service_example_delete_object

The example below deletes the object associated with the objectId: "8948E66F-67DE-441B-A7F8-DAB89965E27C".

data_service_example_delete_object_2

The result of this operation will look as shown below after the Codeless logic runs. As you can see, the object with the name "Bob Smith" associated with the objectId: "8948E66F-67DE-441B-A7F8-DAB89965E27C" has been deleted from the data table.

data_service_example_delete_object_3

You can also delete a record from the data table by passing an object to the operation. The object must have the objectId property and the unique identifier of the record that must be deleted. The example below deletes a record from the data table using an object that contains the following objectId: "FEA94D74-BEA1-4F28-BDDD-FB22CFEB747E"

data_service_example_delete_object_4

The result of this operation is a deleted record from the employees data table:

data_service_example_delete_object_5