40
votes
Accepted
System.AsyncException: Maximum stack depth has been reached
The next lines on salesforce documentation about Queueable interface say the following
You can’t chain queueable jobs in an Apex test. Doing so results in an
error. To avoid getting an error, you can ...
- 17.7k
34
votes
Accepted
Can Queueable solve "Future method cannot be called from a future or batch method"?
Yes, Queueable can be called from Database.Batchable classes. You must go through enqueueJob for this to work:
public class BatchClass implements Database.Batchable<SObject> {
public ...
- 456k
31
votes
Accepted
Can Queueable Apex Jobs Run in Parallel?
Yes, queueable methods can run in parallel. As a proof of concept, here's some code that I wrote:
public class TenSecondQueueable implements Queueable {
public void execute(QueueableContext ...
- 456k
21
votes
Accepted
When passing in a collection of sObjects to a Queueable what values are used?
sObjects (and other objects, for that matter) that are instance variables in Queueables and in Batch Apex classes are serialized and stored, and then deserialized at the time the Asynchronous Apex is ...
- 89.6k
17
votes
Accepted
Salesforce Queueable Interface Chaining LIMIT Error
Since you are calling the first queable from a trigger and the limit shows
Number of queueable jobs added to the queue: 1 out of 1
I believe what is happening is
You save a record and the trigger ...
- 7,808
14
votes
Accepted
DML operation and async Queueable job - which executes first?
Transactions have to be fully ACID compliant. The "C" stands for consistency, and this is where transaction control comes in. In order for your Queueable to execute, it has to be guaranteed that the ...
- 456k
11
votes
Can we callout and chain a Queueable class?
As Dan Appleman notes in the latest edition of Advanced Apex, a Queueable can call a Future method, and a Future method can enqueue a Queueable job. This works in Spring 16, and will allow chaining of ...
- 5,369
11
votes
Accepted
Governor Limits on System.enqueueJob in Asynchronous Apex – Documentation Wrong?
Yes, the documentation in question is incorrect. You can prove that the Limits class does not conform to what is written therein fairly easily:
public class Demo implements Queueable
{
public void ...
- 146k
10
votes
Accepted
Can we callout and chain a Queueable class?
Spring '17 provides:
Make Web Service Callouts from Chained Queueable Jobs
Apex now allows web service callouts from chained queueable jobs. Previously, a queueable job could make a web service ...
- 146k
10
votes
Can Queueable solve "Future method cannot be called from a future or batch method"?
Wasted about 2 months to get an answer from salesforce support why I get
Too many queueable jobs added to the queue: 2
when documentation (https://developer.salesforce.com/docs/atlas.en-us....
- 1,219
10
votes
Accepted
How can my code tell if it's inside a Queueable context?
Spring '16 brings us a new method:
System.isQueueable() which takes care of this requirement.
releasenotes.salesforce.com/en-us/spring16/release-notes/rn_apex_new_classes_methods.htm
As of Spring '...
- 32.2k
9
votes
DML operation and async Queueable job - which executes first?
That's an interesting question. With the queueable execution being asynchronous, could there be a particular timing where the queued job would start executing before the corresponding Callout__c ...
- 100k
9
votes
Accepted
Chaining Callouts and Queueables
The other alternative is to not use Queueable for that purpose. I actually wrote a very fancy Batchable class that did something like that. One interesting design pattern is to make a batch action ...
- 456k
9
votes
Accepted
System.AsyncException: Maximum callout depth has been reached
There is an Idea out there called Allow callouts from chained queueable Apex jobs. Here's the description, with some minor reformatting:
Allow callouts from chained queueable Apex jobs
Currently (...
- 146k
9
votes
Accepted
Enqueue Queueable class multiple times
This pattern is likely to cause tricky-to-debug issues in the future.
When your trigger is invoked via updates made in a Batch Apex class, you will get
an exception stating that you've enqueued too ...
- 89.6k
9
votes
Queuable Apex logic in Constructor or Execute Method
The most important difference would be that constructor is executed in current execution context, and execute method is executed in new one.
In practice it mean that if you call your queueable in ...
- 4,199
8
votes
Accepted
Chaining in Queueable Job
There are really two questions here: chaining and order guarantee.
Chaining is possible by calling System.enqueueJob while inside the execute(Queueable) method, but the documentation also states that ...
- 456k
8
votes
Queuable Apex logic in Constructor or Execute Method
Tl;dr: I don't recommend using a constructor like this.
I think this would violate the principle of least astonishment in a few ways:
Constructor has logic in it (when they're normally used to ...
- 53.5k
7
votes
Accepted
Testing Recursive Queueable Class
This is one of those situations where you have to cheat to get perfect coverage. What you need to do is call your queueable's execute method without actually using the queueing mechanism-- then, the ...
- 456k
7
votes
Accepted
Implement Domain Event Pattern in Apex - can and should it be done?
It's a powerful pattern, and when leveraged properly opens up a completely different programming paradigm. We've used this to do a lot of heavy lifting in consulting, and also to allow different ...
- 32.2k
7
votes
Accepted
Limit of Queueable Jobs Added to the Queue?
See Queueable Apex (emphasis mine):
Chaining Jobs
If you need to run a job after some other processing is done first by another job, you can chain queueable jobs. To chain a job to another job, ...
- 146k
7
votes
Accepted
I want to pass an HttpRequest object to a Class that implements the Queueable interface
Remove the transient keyword. It causes the variable not to get serialized.
Using the transient Keyword
Use the transient keyword to declare instance variables that can't be saved, and shouldn't be ...
- 146k
7
votes
Accepted
Is there a way to chain jobs indefinitely?
According to the Apex Developer Guide documentation on Queueable Apex, there is no depth limit in most org types. The following should probably be amended to include sandbox organizations:
No ...
- 146k
7
votes
Accepted
Queuable Apex logic in Constructor or Execute Method
I would say, the constructor is best used just as "prep". The work you want to enqueue should be done in the execute method.
You always have the option, when constructing a Queueable, to run the work ...
- 10.8k
6
votes
Can Queueable solve "Future method cannot be called from a future or batch method"?
As a workaround you can use Platform Events to publish it from the batch. In that case it would be a 'legal' way to process some work in separate transaction.
And from Platform Event trigger you can ...
- 788
6
votes
Accepted
Test execution order issues with Queueable and @future method
What you describe is an inherent limitation of testing code that runs asynchronously in a future context. When you enqueue your Queueable class to run, you're scheduling it to run at "some time in the ...
- 40.7k
6
votes
Accepted
How can I get around queued job limitations?
You forgot to tell the system that the Queueable class allows callouts. The documentation doesn't really call this out, but you need to use Database.AllowsCallouts, like so:
public class ...
- 456k
6
votes
Accepted
Queueable Apex consideratoins
Having built a "rate-limited multiplexing API engine" before, I can tell you that a robust solution can quickly get very large. We had a complicated system that had the following features:
Throttled ...
- 456k
6
votes
Automated testing of chained Queueable jobs in Salesforce
When you need more than one execution, but you want to test the asynchronous code independently, you can cheat by rolling them back. Here's an example in a unit test:
Test.startTest();
SavePoint sp = ...
- 456k
6
votes
Accepted
How's This for a Simple HTTP Callout Retry Framework?
The only downside is that this may not work for callouts that you need to make from a trigger, because of the 100 scheduled job limit (you can't have more than 100 pending jobs scheduled). A more ...
- 456k
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
queueable-interface × 83apex × 58
callout × 23
queueable-apex × 16
asynchronous × 12
trigger × 11
future × 11
unit-test × 10
batch × 9
asyncapexjob × 8
scheduled-apex × 6
governorlimits × 6
soql × 3
httpcalloutmock × 3
tooling-api × 2
httprequest × 2
design-patterns × 2
apexmock × 2
queueable × 2
apex-flex-queue × 2
asynchronous-testing × 2
visualforce × 1
integration × 1
force.com × 1
data-loader × 1