UnitOfWork not triggering cloud code event handler

Hi everyone,
I have been trying to figure out why the beforeCreate event handler is not being triggered when saving an object with the UnitOfWork/transaction API.

I am using Swift / developing for iOS and have noticed that a singular save() event does trigger the cloud code events as expected, however, when using the equivalent unitofwork.create() method within a transaction, the cloud code event handlers are seemingly not notified.

For example, the following works as expected:
Backendless.shared.data.of(MyClass.self).save(entity: instanceOfMyClass, responseHandler: { savedObject in
print(“Object has been saved: (savedObject)”)
}, errorHandler: { fault in
print(“Error: (fault.message ?? “”)”)
})
}

The following does not:
let unitOfWork = UnitOfWork()
let createMyObjectResult = unitOfWork.create(objectToSave: myObject)
…execute etc.

Any clarity would be appreciated,
Thanks

Hi, Matt. If you use transaction api the ordinary create/update/delete handlers shouldn’t work.
For transactions this special handlers will be made in a future.
The same applies to the RT events.

Hi Oleg, thanks for your reply.
Yeah I thought that may of been the case. Is there any suggested work around at this time? Potentially using a custom event handler?
Thanks

Unfortunately, there should be special event for the UnitOfWork/Transaction.

1 Like

Hi @oleg-vyalyh, I’m just getting started with Backendless but am planning to use transactions in my app. Has this new handler been added yet?

Thanks.

HI @Evan_McDaniel,

There are two handlers now beforeTransaction and afterTransaction:

Regards,
Mark

Great news. Thanks Mark.