I have an apex code which is called from an after trigger. The apex code calls a future method and sometimes the future method runs after the execution of the current thread and sometimes does not.
I want to force the future method to run only when the context of its call ends. So the idea is: when the thread that started the future methods ends, the future methods is allowed to run.
Any ideas? Thanks.