I'm not sure if anyone is able to answer this question (I've been to Salesforce Support already who weren't any help on this issue) but I thought I'd ask it anyway and see if anyone has any ideas how to solve.
Basically, we have various visualforce pages that will run one off code that creates lots of child records for a certain parent record. These records will run their own triggers and so can take quite a while to complete.
My issue is if a user goes to the visualforce page to run the code while it is already being run by another user, at the end of both transactions there will be two sets of child records that have been created. Is there a way to detect when a user is already running code so that I can throw errors if someone is already processing?
I've already tried adding 'for update' keyword onto my SOQL statements but what this does is to pause the second transaction until the first is completed (so the second transaction will eventually execute, which I don't want)