0

Could you please help me with the below queries related to Apex Job Execution:

  1. If multiple Async request(future methods) are fired in the same thread, it makes the Async job request status as Queued for long time, even though the future method has no code inside it. What makes a call to be in Queued state? And what is the limit on the current thread to allow creation of new async calls?

  2. The future method is not triggered(not placed in Apex Job) until the current thread completes the execution. How can we make the future method to be placed inside the Apex Job while the current thread is still running ?

Any idea? Thanks.

2

The notion of a thread is usually not useful in analyzing Salesforce functionality. Instead, think in terms of the transaction: Async Apex is not queued for execution until the transaction commits successfully.

Asynchronous Apex is dequeued and executed based on a variety of factors, including server load. You have no control or visibility into when Asynchronous Apex will be executed, saving if you explicitly schedule it using a Schedulable class.

You cannot cause Asynchronous Apex to run during the current transaction. You can fire a nontransactional Platform Event, which may execute Async Apex Triggers in parallel with the current transaction but also may not. You have no way to deterministically create parallelism on the Salesforce platform.

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.