Is it possible to somehow prevent the deletion of an object in a beforeDelete trigger, without throwing an exception? I want to set the ACLs on the object so that it’s not accessible but still exists in the database, and return a success back to the user. From what I can tell though, this does not seem possible at the moment.
You have to throw an error on BeforeDelete Trigger. If you dont throw error, parse server assume everything ok. And proceeds to delete operation.
You could duplicate the object in afterDelete, change the ACL’s and then save. ObjectId would change though.
As others have already pointed out, that is not possible or at least not intended.
One approach could be to copy the object before deleting and saving it in an
Archive class. However, storing a new object will create a new object ID, which means the object will not be referenced in case the object to is referenced by other objects, for example through Pointers.
Another approach could be to not delete the object but create a Cloud Code function that sets the object ACL so that it is not readable for the users anymore.
Another aspect I should mention is terminology. If you want to “delete” an object, but “not delete it”, then maybe call it “archiving”, “deactivating”, or what best fits your use case. Otherwise, at some point you would “delete a deleted object” which can create all kinds of confusion when maintaining the code later on. Intuitive terminology ensures your code and code comments stay intuitive as well.