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 ...
19
votes
Accepted
Do Platform Event Triggers process synchronously? Do they get a fresh set of limits?
Are the subscription triggers processed synchronously or asynchronously?
Aynchronously
Do the subscription triggers get separate limits from the publishing context?
Yes, separate limits from the ...
19
votes
Accepted
How do I test asynchronous Apex?
Asynchronous Apex includes all of the methods for executing code on the Salesforce platform outside a synchronous transaction, including:
@future methods.
Batch Apex
Queueable Apex
Schedulable Apex
...
Community wiki
18
votes
Accepted
@future runs in test without Test.stopTest() - Can that be?
It sounds like a bug, or at least it is not documented; I would not depend on this behavior. If you want to test asynchronous code, use Test.stopTest(). This applies for Schedulable, Queueable, ...
15
votes
Error "Too many queueable jobs added to the queue: 2"
Salesforce says you can add 50 jobs to the queue per transaction. But what Salesforce doesn't mention clearly is that it is not applicable for batch, you can only enqueue one job. Even if you enqueue ...
13
votes
Accepted
Error "Too many queueable jobs added to the queue: 2"
You have two things going on here:
You can only execute one job from a job.
Triggers fire in chunks of 200 records.
So if you update 201 records, you will have one Queueable kicked off with 200 ...
13
votes
Accepted
Callout Limits for future methods and queueable apex
I quickly wrote a class with future method to test this behaviour.
public class FutureClassLimitsTest {
@future(callout=true)
public static void docallouts(){
for(Integer i=0;i<...
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 ...
11
votes
Accepted
How to run an asynchronous job in developer console?
I suspect you won't be able to get true asynchronous anonymous code working.
The problem is that your anonymous Apex only exists for the transaction it was created in. By the time the asynchronous ...
11
votes
Accepted
Guarantee only a single asynchronous job runs at a time
I've implemented the following in numerous orgs and it works pretty well. It's similar to Keith's suggestion, but a bit more detailed and it does usually do near-realtime processing:
Create a custom ...
10
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 (...
10
votes
Accepted
How to wait for imperative apex call from a LWC to finish running before executing next line?
You would use async/await, as in:
@wire (firstMethodCall, {param1: 'test'})
async wiredResult(result){
console.log('1');
await this.secondMethodCall();
console.log('4');
}
async ...
10
votes
Accepted
Best approach to make callouts from trigger
I wrote an article about this sort of requirement for ApexHours, which you'll find here.
The key points are:
Futures are a real problem to be called from a trigger because you cannot invoke/enqueue a ...
9
votes
Accepted
PB + Queueable System.FinalException: Record is read-only
I suspect that you've unwittingly copied the "isReadOnly" flag on the sObject records. This flag, which can't be accessed or modified directly, is responsible for causing the FinalException that you'...
9
votes
Accepted
In an unit test for an LWC, how can I prove an async chain is setting a value in a lightning-formatted-number?
Figured out a way to flush the promises by applying answer from
https://stackoverflow.com/questions/44741102/how-to-make-jest-wait-for-all-asynchronous-code-to-finish-execution-before-expec
...
8
votes
How to refactor Synchronous code with future method
There is no choice here but to move the "association code" to a method that you call from the end of the future method and the other classes:
public class MyUtilClass {
@future
public static ...
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
Accepted
Why do developers set 'this' to a variable (e.g. 'self' or 'that')?
this is a fickle creature when you're talking about normal functions in JavaScript, because it changes based on context. For example:
let value = {
src: "hello",
output: function() {
...
8
votes
Accepted
Why would a future method not show up in debug logs?
Future methods, once called, are only temporary until a database commit occurs. If an operation causes a partial or total rollback, this will include the future method calls, as well as any emails ...
8
votes
Accepted
Dynamic SOQL Error: Unexpected Token ':' - I have searched for two days, what could I be missing?
The problem lies here:
SELECT :queryFields
You can use bind variables only in the WHERE clause.
Replace this with the actual set of fields.
7
votes
@future runs in test without Test.stopTest() - Can that be?
If you look at the documentation for Test.stopTest(), it says nothing about when asynchronous code does not run. Rather, it simply states that asynchronous is run synchronously when you call Test....
7
votes
@future runs in test without Test.stopTest() - Can that be?
Test.startTest() makes all asynchronous calls synchronous (instant) in Test methods. It helps us in catch any result obtained by the execution of asynchronous calls.
Below is sample example:-
Test ...
7
votes
Parallel callouts in apex
A Queueable chain is probably going to be the best solution pattern for you here, understanding that (as you say) there is not a particularly fluent Salesforce idiom for this kind of processing.
The ...
7
votes
Accepted
What is the life-cycle of static properties in Apex classes?
Static variables are an attribute of a transaction, and will never persist longer than that transaction. They cannot be shared between multiple execution contexts, even if they are running in parallel ...
7
votes
Accepted
Why isn't my platform event chain working?
The code/transaction run by a Platform Event Trigger is run as the "Automated Process" User, and won't show up in logs unless you specifically set up a debug log for the "Automated Process" traced ...
7
votes
How to check if future method has executed
First, asynchronous methods will never even start until the previous transaction commits, so any wait loop would need to be asynchronous itself. Secondly, if you need the status of an asynchronous ...
7
votes
Accepted
Can Database.executeBatch be called from a Queueable started by System.enqueueJob?
Yes, you can do that.
This is my batch class
public class BatchableDemo implements Database.Batchable<sObject>{
public Database.QueryLocator start(Database.BatchableContext bc) {
...
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 ...
6
votes
Why am I not able to get full 60 second CPU time in @future method with getContentAsPDF()
getContentAsPDF actually internally performs a callout back into Salesforce as a new transaction. This means that the actual CPU time used for the primary transaction doesn't account for the time used ...
6
votes
How to run an asynchronous job in developer console?
You might be able to accomplish this by implementing a future class in the org that takes a string and runs it through the Tooling API. This answer has more details.
I've included some things I ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
asynchronous × 325apex × 170
batch × 61
future × 47
callout × 32
lightning-web-components × 31
trigger × 27
unit-test × 25
queueable-apex × 23
scheduled-apex × 20
javascript × 19
governorlimits × 18
asyncapexjob × 17
visualforce × 15
visual-workflow × 15
lightning-aura-components × 14
platform-event × 14
queueable-interface × 12
schedulebatch × 9
promises × 9
queue × 8
exception × 7
continuation × 7
soql × 6
deployment × 6