36 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 ...
user avatar
22 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 ...
user avatar
  • 40.5k
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 ...
user avatar
11 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 ...
user avatar
  • 63k
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 ...
user avatar
  • 438k
8 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 ...
user avatar
  • 144k
7 votes
Accepted

How to delete AsyncApexJob with Queued status

If it's queued that implies its scheduled, therefore you should be able to get the Job ID and abort it, e.g. System.abortJob(jobId);
user avatar
7 votes
Accepted

Getting class name from BatchJob?

You should be able to get the class name by doing this: Select Status, ApexClassId, ApexClass.Name From AsyncApexJob
user avatar
  • 7,857
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 ...
user avatar
  • 438k
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 ...
user avatar
  • 438k
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).
user avatar
  • 144k
6 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 ...
user avatar
  • 438k
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 ...
user avatar
  • 63k
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 ...
user avatar
  • 438k
5 votes

Call Queueable from future method

This will actually a bug in the code. I can see this line - System.enqueueJob(new SecondQueueableApex(counter)); I assume this is calling itself, due to which it starts getting into stack. This ...
user avatar
  • 1,738
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 ...
user avatar
  • 53
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 ...
user avatar
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 ...
user avatar
  • 8,970
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 ...
user avatar
5 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 ...
user avatar
  • 144k
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.
user avatar
  • 3,956
4 votes
Accepted

Testing the ACTUAL batchable context in Database.Batchable methods?

This code compiles indicating Database.BatchableContext is an interface: public class MockBatchableContext implements Database.BatchableContext { private Id jobId; private Id childJobId; ...
user avatar
  • 130k
4 votes
Accepted

Submitted date of apex jobs

You can easily access this info using SOQL. There is an object called AsyncApexJob that contains information about Apex jobs. It will hold several types of jobs (like unit tests, scheduled jobs, etc.)....
user avatar
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 ...
user avatar
4 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 ...
user avatar
  • 87.3k
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 ...
user avatar
  • 130k
4 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, ...
user avatar
  • 438k
4 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 ...
user avatar
3 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 ...
user avatar
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 ...
user avatar
  • 144k

Only top scored, non community-wiki answers of a minimum length are eligible