Skip to content

Bulk Delete Listener

Listeners for bulk deletion work identically to the ones for single deletion. The difference is in the method names to add and remove listener objects:

Conditional bulk delete listener

A conditional bulk delete listener receives an event when an API client uses the bulkDelete API to delete multiple objects in a table with the same whereClause statement as specified by the RT client:

const eventHandler = Backendless.Data.of( 'TABLE-NAME' ).rt();

const callback = ({ whereClause, count }) => console.log( whereClause, count )
const onError = ({ message, code }) => console.log( 'Error:', message, 'Error Code:', code )

eventHandler.addBulkDeleteListener( whereClause, callback, onError );
const eventHandler = Backendless.Data.of( TABLENAMECLASS ).rt();

const callback = ({ whereClause, count }) => console.log( whereClause, count )
const onError = ({ message, code }) => console.log( 'Error:', message, 'Error Code:', code )

eventHandler.addBulkDeleteListener( whereClause, callback, onError );

Unconditional bulk delete listener

A unconditional bulk delete listener receives events when a client uses the bulkDelete API with any whereClause statement:

const eventHandler = Backendless.Data.of( 'TABLE-NAME' ).rt();

const callback = ({ whereClause, count }) => console.log( whereClause, count )
const onError = ({ message, code }) => console.log( 'Error:', message, 'Error Code:', code )

eventHandler.addBulkDeleteListener( callback, onError );
const eventHandler = Backendless.Data.of( TABLENAMECLASS ).rt();

const callback = ({ whereClause, count }) => console.log( whereClause, count )
const onError = ({ message, code }) => console.log( 'Error:', message, 'Error Code:', code )

eventHandler.addBulkDeleteListener( callback, onError );

Both conditional and unconditional event listeners receive the following information in the callback object. The properties listed below are included  into the  object delivered to the listener's callback.

  • whereClause - the where clause value used in the API call to identify the objects deleted from the database.
  • count - the number of objects deleted from the database.

Removing listeners

The method removes all registered listeners for the bulkDelete event:

eventHandler.removeBulkDeleteListeners();

The method below removes all listeners which process events for a specific where clause. The value of the whereClause argument must be the same as one in the addBulkDeleteListener method:

eventHandler.removeBulkDeleteListeners( whereClause );

Removing a specific listener

This method removes a listener identified by the callback object:

eventHandler.removeBulkUpdateListener( callbackObject );