We have a button which takes the next case from a given queue, changes the owner to the logged in user and then displays the case to the customer service rep.
Now, if 2 customer service reps click the button simultaneously it can happen that they both get the case. Of course, only one of them acutually owns the case but they don't know that because it looks like they both own it (a refresh reveals the true owner).
We've tried locking the record using "for update" when fetching the case yet still it seems to be possible to end up with 2 different screens (on one screen the case is owned by user A and on the other it's owned by user B). Again, hitting F5 reveals the actual owner.
I was hoping that when trying to select for update I would get an exception which I could catch and from there do some error handling. However, it seems that either no exception is thrown or, if an exception is thrown, it isn't catchable.
Then I thought that maybe it would be possible to code my way out of it. E.g. using synchronized methods like in Java but it seems that is not yet possible in Apex (see http://forums.sforce.com/t5/Apex-Code-Development/quot-synchronized-quot-where-s-it-documented-Anyway-to-control/m-p/124811).
Has anyone else had a similar issue and if so, how was it solved (if it was solved...)?
Søren Nødskov Hansen