39
votes
Accepted
Cannot delete AsyncApexJob using System.abortJob
EXCEPTION: System.StringException: You can't abort scheduled apex jobs by calling system.abortjob with an AsyncApexJob ID.
You must call system.abortjob with the parent CronTrigger ID.
I tried same ...
24
votes
Dramatic increase in AsyncApexJob latency
When you say "schedule a task", I'm going to assume you're talking about a batch class that performs work. If that's the case, I believe your issue is related to how asynchronous processing works on ...
15
votes
Accepted
Check if an SOQL query is valid without actually executing it
You might be able to accomplish this by executing the query given with an additional LIMIT 0 at the end. You'll still use one SOQL query, but I don't believe this will count against the total number ...
12
votes
How to delete AsyncApexJob with Queued status
In case Phil's solution doesn't work, and you are stuck with a zombie Queued AsyncApexJob, here's a workaround:
At Version 39.0, an attempt to delete a zombie Queued AsyncApexJob that has no ...
11
votes
Accepted
Why should we use Queueable apex when we can perform chaining of batches in batch apex (when we can call another batch in the finish method)
They just have different use cases.
Most crucially, you can have only 100 batch jobs pending at any given time. I do not believe any such limit exists for Queueable jobs.
Queueable jobs will also ...
8
votes
Accepted
What's the difference between AsyncApexJob and CronTrigger?
CronTrigger is the parent job that will be run; it can have many runs attached to it. AsyncApexJob is a single job, including batchable, queueable, and future methods. So, if you want to know what's ...
8
votes
Why queuable apex accepts sobjects where as future methods doesn't?
Batchable, future, and queueable were basically three versions of the same feature request from customers. Initially, customers wanted a way to process bulk data asynchronously. We were given ...
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 ...
6
votes
How is calculated "24-hour period" for the limitation of Asynchronous Apex Executions
It's a rolling window. The start of the range is the same as what you would get from Datetime.now().addHours(-24).
6
votes
Accepted
How can I tell batch job finished executing the finish() method?
So, all my experimentation has come down to this: it appears that the standard interface is technically lying to you; the finish method runs at its leisure sometime after the Completed status occurs ...
6
votes
Accepted
Retrieve a list of currently running jobs
You can easily get the details in apex
Integer enqueuedJobs = [SELECT COUNT() FROM AsyncApexJob WHERE JobType='BatchApex' AND Status IN ('Processing','Preparing','Queued')] ;
You can handle this in ...
6
votes
Accepted
How can I save a class when a batch job is running (without the Ant tool)
Setup | Deployment Settings | Allow deployments of components when corresponding Apex jobs are pending or in progress.
Caution: Enabling this option may cause Apex jobs to fail.
The above applies ...
6
votes
Why should we use Queueable apex when we can perform chaining of batches in batch apex (when we can call another batch in the finish method)
Queuable Advantage:
Queueable can run parallelly and there no limit for chaining. While in a batch there is a limit of 100 batches
Queueable can be much faster than batch apex if used properly
This ...
6
votes
Accepted
Method not getting called after addError, Please advise
The only way to persist anything from a transaction that fails is to use a Platform Event. Crucially, you need this Platform Event to publish immediately, not when the transaction finishes. Define a ...
5
votes
Accepted
AsyncApexJob table has additional record initially? platform bug?
See What are the differences between the different possible jobs processed in the 'AsyncApexJob' object? for more information on jobs, but specifically they cover ApexToken:
An 'ApexToken' job is ...
5
votes
Can't I use ALL ROWS in asynchronous Salesforce queries?
It sounds like there was a discussion with someone in Salesforce that the Bulk API wasn't the right tool for monitoring deleted records.
There is always the Data Export functionality. It's kind of ...
5
votes
Accepted
Why salesforce has introduced Queueable Apex. need some proper clarification
This is broad questions but let me try to give you summery
1) You can pass Array of objects to Queueable in future you can not.
2) You can chain jobs in Queueable in future you can not.
Ex. You ...
5
votes
System.LimitException: Too many async calls created: 2
We ran into this issue with Summer 16 and have opened a ticket with Salesforce. They acknowledge the issue is happening due to release and their R&D team is working on it.
I'm going to ask ...
5
votes
Cannot delete AsyncApexJob using System.abortJob
Turns out that I had to open a case with Salesforce to solve this. After more than 10 days, and two escalations, they didn't solve the issue. Since I didn't want to waste more time waiting for a ...
5
votes
Accepted
Why queuable apex accepts sobjects where as future methods doesn't?
The possibility of data going stale is not why future methods do not accept sObject parameters. Id values are future-compatible primitives and can also be stale, if, for example, the record is deleted ...
5
votes
Accepted
What user is queueable apex class running as?
The user who initiates the queueable call will be the running user. This is generally true for the other asynchronous types, as well (e.g. Scheduable, Batchable). There are a few exceptions, though, ...
5
votes
Accepted
How to avoid running a batchable when an instance is already running?
Strap in! It's a long haul...
1. Has it worked well for you?
On its own, testing AsyncApexJob before starting a batch is prone to race conditions and will fail you on any implementation of scale.
...
4
votes
Cannot delete AsyncApexJob using System.abortJob
You may have to contact Salesforce support to fix this. They may be able to kill that queued job. We've had a similar issue in the past and we could only solve it by contacting SF.
4
votes
Accepted
Can't Save Class (batch or future jobs pending or in progress)
I finally found a hack to work around the issue and save my class. In short:
Delete that class from your org and then save it back to server using
your IDE.
More Details/Explanations:
Just to ...
4
votes
ApexTestRunResult's status is set to complete and all tests pass, but the enqueued and completed count do not match
From the ApexTestRunResult docs:
MethodsCompleted
The total number of methods completed during the test run. This value is updated after each class is run.
I'm seeing this discrepancy as well ...
4
votes
Accepted
Is asynchronous apex either rolled back or not executed if the original transactions fails?
My understanding is that for most asynchronous invocations - including future, Queueable, Batchable, Schedulable - the invocation enqueues the operation but it does not execute until the end of the ...
4
votes
what is the parameter database.batchablecontext?
Personally, I've never used that parameter. But it is described in BatchableContext Interface as:
BatchableContext InterfaceRepresents the parameter type of a batch
job method and contains the ...
3
votes
Accepted
Test.stopTest() does not run @futureJob called from an enqueuedJob
Calling Test.stopTest() only forces any asynchronous processing which is already enqueued to fire. It does not affect any subsequent asynchronous processing kicked off by those jobs.
|-------------...
3
votes
Can a future method conflict with a queuable method?
This sort of situation is exactly what the FOR UPDATE clause is for:
Locking Statements
In Apex, you can use FOR UPDATE to lock sObject records while they’re being updated in order to prevent ...
3
votes
Accepted
Is an AsyncApexJob record inserted immediately at the end of a transaction?
I just tested this, and it's available immediately in the same transaction, before the current transaction completes. Obviously, this Id won't be available to other transactions before "final commit," ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
asyncapexjob × 95apex × 49
batch × 27
scheduled-apex × 19
asynchronous × 18
scheduled-job × 10
future × 8
queueable-apex × 8
queueable-interface × 8
governorlimits × 6
unit-test × 4
schedulebatch × 4
cron × 4
visualforce × 3
trigger × 2
query × 2
callout × 2
transaction × 2
queueable × 2
lightning × 1
soql × 1
community × 1
rest-api × 1
api × 1
managed-package × 1