I have a button that calls a very complex feature that caused salesforce limits to be reached. I modified the method in asynchronous (@future) and added two states: "waiting" and "not processed".
The first state is used to indicate the time between the click on the button and the execution of the @future method. The second is used in case of problems in the execution of the method.
My problem is the concurrency, if a user opens the same object in two tabs and clicks on the button in both tabs, execute both methods and insert double the records.
I included a check in the future method that before starting check if they have already been created but it does not work. I always get double insertion.
How can i solve this problem?