How can I best check where an object is committed?

0
I have an order process in which I allow an anonymous user to create a new order via a deeplink and do quite some stuff in an after create. When the guest closes the browser an empty order has been committed to the database which makes me end up with invalid records. I know that an ID is stored in the db when an object is created, but thought it would be removed when the object is not committed. Questions I have are a 1. Should the object normally be deleted from the db in this scenario? and 2. How can I best find out when the object is committed other than using the advanced find and following the logic?
asked
2 answers
3

To provide an answer to both of your questions:

1) Yes this is the normal behaviour, in order to start editing an object you need to create it first so at that time an object is created in the database.

2) You can use basically need a schedueled event each night that cleans out your orders that have certain required fields not filled. If you have no required fields than you use a boolean as Roberto suggested. Set this boolean at the end of your registration process so that you can determine if it is complete.

In addition to checking the required field/boolean i would suggest to also check the creation date as you do not want to clean out empty objects in your schedueled event that are only just created as someone might still be using that object.

answered
0

I use the IsNew() function to check if an object is new (= not committed). Does that help?

answered