Skip to content

Object/File Counts

Backendless version 5.x introduces new API to calculate total number of objects and files in a remote collection. In the previous version of Backendless, that number was included as a property of the returned collection. See the examples below:

Version 3.x

IDataStore<Map> contactStorage = Backendless.Data.of( "Contact" );

BackendlessDataQuery dataQuery = new BackendlessDataQuery();
dataQuery.setWhereClause( "age > 21" );
contactStorage.find( dataQuery, new AsyncCallback<BackendlessCollection<Map>>()
{
  @Override
  public void handleResponse( BackendlessCollection<Map> foundContacts )
  {
    Log.i( "MYAPP", "Total number of objects matching query - " + foundContacts.getTotalObjects() );
  }

  @Override
  public void handleFault( BackendlessFault fault )
  {
    Log.e( "MYAPP", "Server reported an error " + fault.getMessage() );
  }
} );

Version 5.x

IDataStore<Map> contactStorage = Backendless.Data.of( "Contact" );

DataQueryBuilder queryBuilder = DataQueryBuilder.create();
queryBuilder.setWhereClause( "age > 21" );
contactStorage.getObjectCount( queryBuilder, new AsyncCallback<Integer>()
{
  @Override
  public void handleResponse( Integer objectCount )
  {
    Log.i( "MYAPP", "There are " + objectCount + " objects matching the query" );
  }

  @Override
  public void handleFault( BackendlessFault fault )
  {
    Log.e( "MYAPP", "Server reported an error - " + fault.getMessage() );
  }
} );

Additional resources: