1

is there any functionality in the salesforce that we can set order of the future methods?

someone just told me that we can do that and i was looking for that but could not find any solution.

workaround i know : if any object is getting updated on one future method then we can write trigger to call another future method.

but is there any other way?

Note : i am just exploring this scenario for learning purpose.

Thank you in advance.

  • If a trigger is run as a result of a future method you cannot then cause another future method to execute. This will throw an error that a future cannot be called from a future – Eric Aug 2 '19 at 5:52
3

@future methods are enqueued in a message queue that doesn't guarantee order of delivery. While they will often run in the order they're enqueued in there's no guarantee of that, and out of order execution is certainly possible.

Your idea of "chaining" future methods works better with Queuable jobs, since they can directly enqueue each other.

Also, for the sake of timing be aware that @future, Queueable, and other forms of async Apex are only enqueued for execution when the request that enqueued them completes since enqueued work is rolled back if the request fails.

  • "Also, for the sake of timing be aware that @future, Queueable, and other forms of async Apex are only enqueued for execution when the request that enqueued them completes since enqueued work is rolled back if the request fails." i did not get this. can you explain please. thanks – patelkiran3090 Aug 2 '19 at 4:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.