Skip to content

Deleting Multiple Objects

This API deletes multiple objects in a data table with a single request. Consider the following example, it demonstrates an API call which deletes all objects in the Person data table where the value of the age property is greater than 20:

Backendless.Data.of( "Person" ).remove( "age > 20", new AsyncCallback<Integer>()
{
  @Override
  public void handleResponse( Integer objectsDeleted )
  {
    Log.i( "MYAPP", "Server has deleted " + objectsDeleted + " objects" );
  }

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

Blocking API

public int Backendless.Data.of( "TABLE-NAME" ).remove( 
                           String whereClause ) throws BackendlessException
public <E> int Backendless.Data.of( E ).remove( 
                           String whereClause ) throws BackendlessException

Non-Blocking API

public void Backendless.Data.of( "TABLE-NAME" ).remove( 
                           String whereClause,
                           AsyncCallback<Integer> responder )
public <E> void Backendless.Data.of( E ).update( 
                           String whereClause,
                           AsyncCallback<Integer> responder )

where:

Argument                Description
TABLE-NAME Name of the table where the objects expressed via java.util.Map instances will be updated.
E Java class of the data objects to update in the database.
whereClause A condition for selecting objects to be deleted in the data table.
responder a responder object which will receive a callback when the method successfully deleted the objects or if an error occurs. Applies to the non-blocking method only.

Return Value

The method returns the number of objects deleted in the database.

Codeless Reference

data_service_bulk_delete

where:

Argument                Description
table name Name of the data table where objects will be deleted from.
where clause A condition for selecting objects to be deleted in the data table. Refer to the Search With The Where Clause topic for more information.

Returns the number of deleted objects.

Consider the following records in the employees data table:

data_service_example_delete_object_3

The example below is set to delete all values from the position column that match the where clause condition, (e.g. 'Manager'). In this case, the condition acts like a filter and deletes all values that match the criteria 'Manager'.

data_service_example_bulk_delete

The result of this operation will look as shown below after the Codeless logic runs. As you can see, two records containing the 'Manager' value in the position column were deleted from the data table.

data_service_example_bulk_delete_2

Also, the operation has returned the number 2, indicating the number of deleted objects in the employees data table.

data_service_example_bulk_update_4