Support Topics Documentation Slack YouTube Blog

Prevent user deletion using handlers

Backendless Version (3.x / 5.x, Online / Managed / Pro )


Client SDK (REST / Android / Objective-C / Swift / JS )


Application ID


Expected Behavior

  1. interfer when trying to delete a user and run a custom code using cloud code.

Actual Behavior

I added two types of handlers, on for before user remove and another before table remove.

both are ignored when deleting a user using the following code in cloud code.

return Backendless.Data.of(Users).remove(objectId);

Reproducible Test Case

  1. add handlers
  2. run the code above to remove a user


  1. I didn’t understand if ‘non-blocking’ is needed to I tried with and without.
  2. before find handler does work and I see in the console.
[debug:backendless] 16:01:36.032 [b014....e3d] [INVOKE HANDLER] persistence.beforeFind (*)
  1. the two handlers mentioned above are registered for sure but are not invoked
[debug:backendless] 15:58:13.847   user.beforeRemove  (lib/handlers/delete-users.js)
[debug:backendless] 15:58:13.847   persistence.beforeRemove (*) (lib/handlers/delete-users.js)
[debug:backendless] 15:58:13.847   persistence.beforeFind (*) (lib/handlers/find-all.js)

I might am missing something because before load relations also doesn’t seems to work as I expect.

although handler is registered - when performing load relations it is not called.

Hi Eran,

How did you verify that the event handler is not invoked?

I created and deployed a simple beforeRemove event handler in codeless (which results in a JS handler from the implementation perspective). Here’s what it looks like:

Then I invoked the deletion API using REST Console. The deletion succeeded:

Here’s the log from the execution of the event handler:

21:01:52 | SERVER_CODE | INFO | [5299] Building ServerCode Model for path (/opt/backendless/repo/840386aa-ff5c-8c9f-ff46-943134b88e00/files/servercode/CODELESS/default/PRODUCTION)
21:01:52 | SERVER_CODE | INFO | [5299] ServerCode Model built in 7ms
21:01:52 | SERVER_CODE | INFO | [5299] [14f3f6c6-8525-4518-8e85-68a8a9cd4662] [INVOKE HANDLER] user.beforeRemove
21:01:52 | SERVER_CODE | INFO | [5299] in before remove
21:01:52 | SERVER_CODE | INFO | [5299] 3AA880DE-BE6C-49EA-B9B5-B1D0082CCF40
21:01:52 | SERVER_CODE | INFO | [5299] Processing finished in 34.912ms


Hi Mark,
Thanks you checking this one out. I have used the javascript sdk and added code to short circuit the request. I will double check myself.

But you can see that it is still happening for beforeLoadRelations

  1. added code to register to beforeFind and beforeLoadRelations
  2. both are registered correctly
  3. beforeFind is handled while beforeLoadRelations is being ignored
  4. I printed the query options to show that user requested to load relations (and managed to do so)

Hi @mark-piller, did you have a chance to see my response. I would like to add server side logic that rely on the handlers before delete update create and bulk (as I implement multi-tenant service that should either add the organization value using handlers or verify user can delete / update / bulk action them.

I feel like I’m missing something and not necessarily found a bug.

Please assist.

Question, I saw that there are limitation on the number of handlers/services, maybe it applies also during deployment and you just ignore my handlers that are connected from the IDE?

Hello @Eran_Sakal

Can you provide a code where you invoking a beforeLoadRelations handler?

Is it looks like this?
Backendless.Data.of('tableName').loadRelations(objectId, query)

Regards, Dima.

Hi @Dima_Vak I actually did it in the Console playground, see second reply in this thread for more details.

In Console, you retrieve a table with params that you choose, it’s triggered ‘find’ handler. But if want to trigger ‘loadRelations’ you must use the method from SDK - loadRelations, its external API.
Example here - Relation Paging - Backendless SDK for JavaScript API Documentation

Regards, Dima