Skip to content

Basic Object Retrieval

Backendless supports multiple data search and retrieval operations. These include finding an object by its objectId, finding first or last object in the collection or retrieving the entire persisted collection.

Retrieving Data Objects

Methods

Retrieve data objects with the default paging setting from a table:
Future<List<Map>> Backendless.data.of("TABLE-NAME").find([DataQueryBuilder queryBuilder]);
Find first data object from a table. The first data object is the first one saved in the data store:
Future<Map> Backendless.data.of("TABLE-NAME").findFirst({List<String> relations, int relationsDepth});
Find last data object from a table. The last data object is the last one saved in the data store:
Future<Map> Backendless.data.of("TABLE-NAME").findLast({List<String> relations, int relationsDepth});
Find a data object by its ID:
Future<Map> Backendless.data.of("TABLE-NAME").findById(String id,
      {List<String> relations,
      int relationsDepth,
      DataQueryBuilder queryBuilder});
Retrieve data objects with the default paging setting from a table. Returned list will contain objects of type E (the name of the class must match the name of the table):
Future<List<E>> Backendless.data.withClass<E>().find([DataQueryBuilder queryBuilder]);
Find first data object of class E. The first data object is the first one saved in the data store:
Future<E> Backendless.data.withClass<E>().findFirst({List<String> relations, int relationsDepth});
Find last data object of type E. The last data object is the last one saved in the data store:
Future<E> Backendless.data.withClass<E>().findLast({List<String> relations, int relationsDepth});
Find a data object by its ID:
Future<E> Backendless.data.withClass<E>().findById(String id,
    {List<String> relations,
    int relationsDepth,
    DataQueryBuilder queryBuilder});

where:

Argument                Description
TABLE-NAME Name of the table from where the data is retrieved from.
E Java class identifying the table where from where the data must be loaded from. For example, if the table is "Person", the argument should Person.class..

Example

The following code demonstrates various search queries:

Load contacts using default paging

Backendless.data.of("Contact").find().then((foundContacts) {
  // every loaded object from the "Contact" table is now an individual Map
});

Find first contact

Backendless.data.of("Contact").findFirst().then((contact) {
  // first contact instance has been found
});

Find last contact

Backendless.data.of("Contact").findLast().then((contact) {
  // last contact instance has been found
});

Find contact by objectId

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

Backendless.data.of("Contact").save(contact).then((savedContact) {
  // now retrieve the object using it's objectId
  Backendless.data.of("Contact").findById(savedContact["objectId"]).then((response) {
    // an object from the "Contact" table has been found by it's objectId
  }); 
});
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 demonstrates various search queries:

Load contacts using default paging

Backendless.data.withClass<Contact>().find().then((foundContacts) {
  // every loaded object from the "Contact" table is now an individual Map
});

Find first contact

Backendless.data.withClass<Contact>().findFirst().then((contact) {
  // first contact instance has been found
});

Find last contact

Backendless.data.withClass<Contact>().findLast().then((contact) {
  // last contact instance has been found
});

Find contact by objectId

Contact contact = Contact()
  ..name = "Jack Daniels"
  ..age = 147
  ..phone = "777-777-777"
  ..title = "Favorites";

Backendless.data.withClass<Contact>().save(contact).then((savedContact) {
  // now retrieve the object using it's objectId
  Backendless.data.withClass<Contact>().findById(savedContact.objectId).then((response) {
    // a Contact instance has been found by objectId
  });
});