function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Don't allow user to edit multiple cases

I have a scenario where users will be taking ownership of some cases by checking the checkbox and clicking the button. The problem I am facing here is if multiple users select the same case at the same time to work on an error should be thrown  to all the users except the first one saying this case is already taken by other user to work. I really don't understand how to implement this logic in my visualforce page. I cannot post my code as it is too long and snippet to implement the above scenario is much appreciated. Thanks. 
Eli Flores, SFDC DevEli Flores, SFDC Dev
It sounds like you just need to requery before reassigning it in the save method.

public id selectedCaseID {get;set;}
public PageReference setCaseOwner(){
List<case> caseBeingTransfered = [SELECT ID, OwnerID FROM Case WHERE ID = :selectedCaseID];
if (!caseBeingTransfered.isEmpty()){//we do this to avoid tossing an error if the case was recently deleted.

  if (caseBeingTransfered.OwnerID != queueID) {
    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,Label.RecentlyReassignedCaseMsg));//use custom labels to let admins customize the message to their user base
  } else {
   case caseBeingTransfered.OwnerID = userID;
   update case;
} else {
  ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,Label.CaseMissingMsg));//use custom labels to let admins customize the message to their user base