Let's say, there are two case types in your application - W- and C-.
In the W- case processing, we want to update C- case in real time. For this, I have created an activity that does Obj-Open C- with a lock, Property-Set, Obj-Save and Commit and placed this activity in the post processing in Flow Action of W- case type.
It works fine most of the times, but I just noticed it throws an error as below when C- case is actually locked by someone else.
This error makes sense because C- is a different case type and it could happen - someone else may have it opened for an update. What would be the best practice to handle such situation? Should I implement some logic to loop and check if lock is held with a certain time? If so, can someone show me a sample code?
While using Update Case smart shape, always remember that it does NOT handle locking scenario. If the other case you are trying to update is locked, it will fail for sure.
1. As mentioned by Kiruthika already, you can queue the update task to a queue processor with multiple retry attempt configured, to get it done in asynchronous mode. But, I think your requirement is to do it immediately.
2. (This is what I followed in one of my projects) Assuming the other case will be updated upon completion of an assignment of current case - In post activity of your flow action, try to take the lock on the case first. If it fails, don't try to proceed any further with update work. Set an error message on the page that clearly indicates who (the actual user name/id, and NOT requestor id) has a lock on the other case.
3. Change the locking mechanism of the other case to optimistic.
Explain pros and cons of each approach to your client and get to an agreement. I would personally prefer option 2 as it is easy to develop and maintain as well.