I have a screen flow that is included in a lightning record page. At some point it executes a callout to an external system. The scenario that I would need to avoid is to have multiple users open the flow and execute the callout at the same time.
The only way to avoid this that came to mind is the following:
- Create a new custom field on the object, that will be used as a flag;
- Query the flag when the flow gets opened;
- When the callout gets executed, send the value of the flag from the flow to the controller;
- Before the callout gets executed, query the flag from the database and check if it's different from the value sent from the flow. If it is, then the callout has been executed already by another user;
- After checking if the flag got changed(but before the callout), update the flag to the current date time;
The problem that I am facing is the fact that the callout needs to be executed synchronuously, but the DML needs to be executed before the callout. Still, since DMLs cannot be executed before callouts, I'm pretty much stuck at this point.
How can I avoid having the same flow element being executed in parallel by multiple users?