Questions tagged [asynchronous]

An asynchronous process is a process or function that executes a task "in the background" without the user having to wait for the task to finish. Typically, you will use Asynchronous programming for callouts to external systems, operations that require higher limits, and code that needs to run at a certain time.

Filter by
Sorted by
Tagged with
36 votes
10 answers
2k views

How can I cause side effects outside an execution context?

I've got a scenario that relies on the system's "automatic rollback" behaviour to undo any DML, emails, futures and so on, in the case of an error. Basically, by allowing code to throw an unhandled ...
Matt and Neil's user avatar
27 votes
4 answers
26k views

Can Queueable solve "Future method cannot be called from a future or batch method"?

I have code that must be called as @future as it requires all the resources one can get. The only problem is that in 1% of the cases this code is called from a Batch and therefore fails with System....
Robert Sösemann's user avatar
27 votes
1 answer
5k views

Dramatic increase in AsyncApexJob latency

Problem Salesforce is a multi-tenant platform and as a consequence the time for an asynchronous request to be dequeued may vary. This is not a problem for us, as long as the delays stay within ...
Sam Theisens's user avatar
22 votes
4 answers
4k views

@future runs in test without Test.stopTest() - Can that be?

For the last years I expected all async Apex means not to run in tests when there is no Test.stopTest() in my test code. But now I have a test without this call and a future method is called. I ...
Robert Sösemann's user avatar
22 votes
1 answer
975 views

Why use Platform Events in standalone native apps?

In Summer '17 Salesforce released Platform Events - a native messaging system accessible via Apex and several APIs. I assume the main use case for such a feature is to allow integration of Salesforce ...
Robert Sösemann's user avatar
17 votes
1 answer
3k views

Do Platform Event Triggers process synchronously? Do they get a fresh set of limits?

I'm intrigued by Platform Events, but I have a few questions about how they operate: Are the subscription triggers processed synchronously or asynchronously? The developer guide makes it clear that ...
Adrian Larson's user avatar
  • 149k
16 votes
2 answers
6k views

Governor Limits on System.enqueueJob in Asynchronous Apex – Documentation Wrong?

Is there any execution context which uses asynchronous governor limits and allows up to 50 jobs to be queued with System.enqueueJob in a single transaction, or is Salesforce’s documentation just wrong?...
Sequoyah's user avatar
  • 760
15 votes
1 answer
12k views

Using Batch Apex on millions of records

Part of our app behaviour is going over millions on records and updating their data. From what I read, we can do it using Batch Apex although I am not certain I fully understand how it works. Here ...
Uri Lukach's user avatar
  • 1,254
15 votes
1 answer
8k views

How do I test asynchronous Apex?

This is a canonical question and answer developed by the community to help address common questions. If you've been directed here, or your question has been closed as a duplicate, please look through ...
15 votes
3 answers
1k views

Batch Apex in AppExchange package and orgs with related triggers that call @Future methods

Here's the problem: when an org has a trigger that calls an @Future method, any batch Apex that fires that trigger will fail, since you cannot call an @Future method from an @Future method OR from ...
Adam's user avatar
  • 4,308
15 votes
1 answer
1k views

How to archive & restore Custom Objects in Big Objects

For my app I want to build a Archive and Restore functionality. For a given Custom Object MyObject__c and a Big Object ArchivedMyObject__b those requirements need to be fulfilled: MyObject__c records ...
Robert Sösemann's user avatar
12 votes
2 answers
15k views

What does the Batch Apex "Holding" status mean and where is it documented?

I've seen the following values in the AsyncApexJob table during the 'cradle to grave' life cycle of a Batch Apex job: BEFORE running: Queued Preparing WHILE running: Processing AFTER running: ...
Matt and Neil's user avatar
12 votes
4 answers
1k views

Run more than one async jobs from Future/Quable context

We have created a process which must work asynchronously (limits and architecture reasons) and it was working fine. Some time later we have started to work with BigObject. And as long as writing to ...
Mattue's user avatar
  • 123
12 votes
1 answer
3k views

Testing scheduled apex containing @future method?

I've seen plenty of posts and documentation on testing asynchronous apex in general, but what about code with multiple layers of asynchronous code? Specifically, I have a scheduled apex class which ...
smohyee's user avatar
  • 3,732
11 votes
3 answers
40k views

Error "Too many queueable jobs added to the queue: 2"

I've been looking for similar questions, but none of them applies to my scenario, so I'd be grateful if you can explain me why my logic is failing, and what can I do in order to fix it. I want to run ...
user3529582's user avatar
11 votes
1 answer
657 views

Why do we have higher apex async executions on days we deploy to Production?

We call the following endpoint at the same time each day to get a count of our daily async executions to track our usage. /services/data/v50.0/limits The following response gives us the # of daily ...
Kris Goncalves's user avatar
10 votes
2 answers
11k views

How to run an asynchronous job in developer console?

I want to find a quick way to be able to run ad-hoc pieces of Apex code asynchronously in developer console so I have higher limits. I want to be able to write and update this code quickly (no sandbox ...
Jorjani's user avatar
  • 2,192
10 votes
2 answers
1k views

Guarantee only a single asynchronous job runs at a time

This is a bit of an odd one. We are interacting with an external system that does not support concurrency due to a bug which they are struggling to fix. We perform a HTTP callout, the callout takes ...
Mattisdada's user avatar
  • 1,071
10 votes
1 answer
1k views

Are @future methods ignored in @TestSetup blocks?

Ok, this is going to become a quite long question. The main goal is to document strange platform behavior and maybe learn more why this happens. It all started with that test which failed because ...
Robert Sösemann's user avatar
10 votes
0 answers
795 views

Implement Domain Event Pattern in Apex - can and should it be done?

In Domain Driven Design a single pattern is drawing a lot of attention to itself - Domain Events and Event Queues. (slide via http://de.slideshare.net/andysal/never-mind-the-bollocks-heres-the-domain-...
Robert Sösemann's user avatar
9 votes
2 answers
17k views

Callout Limits for future methods and queueable apex

I'm aware from the docs that "A single Apex transaction can make a maximum of 100 callouts to an HTTP request or an API call." Is anyone aware if that limit is higher in a future methods or ...
Tyler Zika's user avatar
  • 2,808
8 votes
2 answers
4k views

System.AsyncException: Maximum callout depth has been reached

I have a System.Queuable job, on a particular Sandbox that is giving me issues. It works fine on other Orgs, but fails on this particular one. The job structure is this: Batch Apex job calls System....
Phil Hawthorn's user avatar
8 votes
3 answers
4k views

Can a DML retry solve UNABLE_TO_LOCK_ROW race conditions?

I have 2 Batch classes working on different child objects of a common master object. Batch Batches are started parallel to speed up this long running cleansing operation. It depends on the underlying ...
Robert Sösemann's user avatar
8 votes
1 answer
9k views

How to wait for imperative apex call from a LWC to finish running before executing next line?

I have two methods seen below, the first method is a wired call: @wired (firstMethodCall, {param1: 'test'}) wiredResult(result){ console.log('1'); this.secondMethodCall(); ...
user2821694's user avatar
8 votes
3 answers
2k views

Build Custom Batch Queue to centrally manage Batches & circumvent the Max. 5 Batches in parallel

Just assume you had an app that would have to process huge amounts of records in an org in multiple ways each day. For each "way" you have a separate Batchable class and those are triggered ...
Robert Sösemann's user avatar
8 votes
4 answers
3k views

Parallel callouts in apex

On some user action, I am calling several different third party services in order to update data in salesforce. As these callouts are time consuming, I would like to execute them in parallel, and when ...
Nikola Okiljevic's user avatar
7 votes
3 answers
424 views

Is there a clever abstraction to convert Lightning Component action responses to promises?

Coming from Angular and Ember, where making Ajax requests resulted in a Promise, I find it a little disappointing and frustrating that SFDC wants me to get back into callback hell by setting callbacks ...
Brian Kessler's user avatar
7 votes
1 answer
3k views

Do triggers run asynchronously when triggered by DML in apex?

The question is fairly self-explanatory, but to add a little background, here's the scenario that has made me ask. First a (very basic) SSCCE: public void createAttachments(List<Account> ...
DaveyDaveDave's user avatar
6 votes
3 answers
2k views

How to best structure code so it can be run synchronously and in Batch

This question is somewhat related to my other open question on the asynch/synch topic. Assume I would have an algorithm that could tell me that for a given customer org (data volumes and other ...
Robert Sösemann's user avatar
6 votes
2 answers
977 views

Queueable Apex consideratoins

This is more of a theoretical question and probably goes more to design and I hope I can do this justice. I have successfully coded in apex multiple triggers which make callouts using the @future (...
Daryn's user avatar
  • 251
6 votes
2 answers
2k views

How can my code tell if it's inside a Queueable context?

To go with the new System.Queueable interface, I'm looking for the analogy of: System.isBatch() System.isFuture() System.isScheduled() Is there a System.isQueued() or something?
Matt and Neil's user avatar
6 votes
2 answers
1k views

PB + Queueable System.FinalException: Record is read-only

I've set up a Process (in Process Builder) which calls an invocable method, but cannot figure out why I'm getting this error: System.FinalException: Record is read-only I'm familiar with the ...
Mike's user avatar
  • 1,179
6 votes
2 answers
1k views

How to test @future methods with setup objects and avoid MIXED_DML_OPERATION

I’m in a situation where I have to use a future method to avoid MIXED_DML_OPERATION error. I have a trigger that runs after INSERT on USER and creates a custom object X. They are in 1:1 relation. ...
user682217's user avatar
  • 1,171
6 votes
3 answers
4k views

How to estimate how long a given batch will run?

Are there any reliable numbers, heuristics, experience reports to estimate (and display it to the triggering user) how long a given batch will run? Sure the time will mainly depend on the number of ...
Robert Sösemann's user avatar
6 votes
2 answers
2k views

Rerender apex:details after DML async method call

I have found a strange behaviour and I can't find why does it happening. I have custom object Test2_c with custom text field Status_c. I want to change it's status asynchronously, so I prepare a VF ...
dpedro's user avatar
  • 171
6 votes
2 answers
611 views

How to mix getContentAsPDF calls with DML?

This critical update: PageReference getContent() and getContentAsPDF() Methods Treated as Callouts will be auto-activated in January 2016. We have some code that uses a queue of custom event ...
Keith C's user avatar
  • 134k
6 votes
1 answer
3k views

Is a synchronous method call possible in Lightning Components?

A Lightning Component - lets call it component B - can define a method (that can have arguments) like this: <aura:method name="doAbc" action="{!c.doAbc}"/> that can be called from another ...
Keith C's user avatar
  • 134k
6 votes
2 answers
1k views

DML Error on new Asynchronous Record-Triggered Flow

We've recently developed a record triggered flow that retrieves data via callout when a certain field is set, using Salesforce's new Asynchronous Record-Triggered Flow. The issue we're having is, that ...
Carl-Johan's user avatar
5 votes
1 answer
4k views

How can I get the details of last schedulable job and of which class? Is there any way?

I have a requiurement where I have to get the details of last job details and the Of which clas s. How can I get the details ? i have tried using CronJob details and CronTrigger?
AnkushSalesforce's user avatar
5 votes
2 answers
1k views

Enforce Batches (whole run, not single jobs) to wait for each other

A few situations in my app trigger a Clean up batch to run. It will process many records. In some situations multiple of such Cleanup batches will be triggered by independent user operations. If the ...
Robert Sösemann's user avatar
5 votes
2 answers
2k views

Do asynchronous methods run in parallel?

The short question is - do future methods run in parallel, or sequentially? I am wondering if race is possible in Salesforce. Let's say We've got some singleton class S that we want to call from some ...
Bart Juriewicz's user avatar
5 votes
1 answer
1k views

How can I synchronize processing in Apex?

I have a custom Object TaskEvent with an Event Type and a Task ID Throughout the life-cycle of the task I will receive events such as Start Event Routing Event End Event I receive a web request ...
ScArcher2's user avatar
  • 182
5 votes
2 answers
343 views

How to disable asynchronous jobs so that they cannot update data

There will be a data export happening from our org for large number of objects and records using a cloud based ETL tool. We have a business scenario where we need to make sure that there is no data ...
Walker's user avatar
  • 2,313
5 votes
2 answers
740 views

Spin locks with variable time retry backoffs

Use Case After insert triggers start Queueable Queueable execute() contends for same resource, uses spin lock to wait for resource availability. Many queueables could be running at same time. ...
cropredy's user avatar
  • 69.1k
5 votes
1 answer
2k views

Are aura:waiting and aura:doneWaiting component specific events?

Good afternoon everyone, I have a question regarding the use of the aura:waiting and aura:doneWaiting system events. I currently have two nested child components within a container component as you ...
Daniel Fuller's user avatar
5 votes
3 answers
543 views

Tracking errors in batch impossible as Dev Console stops logging or breaks with Server error

When single batch jobs fail only the last one is party shown in the Apex Logs page. This is not enough for debugging. A better way ist to check the log entries that are written per batch execute. ...
Robert Sösemann's user avatar
5 votes
1 answer
2k views

LWC multiple apex calls on initialization (Best practices question)

PROBLEM: I have a LWC component which needs to gather data from different objects on initialization event (Objects are: custom object, files and metadata type). This is what I have in place working ...
Alex Cortes's user avatar
4 votes
2 answers
2k views

In an unit test for an LWC, how can I prove an async chain is setting a value in a lightning-formatted-number?

I am trying to prove that the price is being set on the component. I have the following HTML: <template> <h1>Current price of a bitcoin in Euro</h1> <lightning-formatted-...
Brian Kessler's user avatar
4 votes
2 answers
2k views

Send out email when Apex Queueable fails and test it

This question definitely is a duplicate of many questions here, but after reading most of them I am still somewhat clueless. Question 1: why I can't just catch exceptions in the execute and send an ...
Robert Sösemann's user avatar
4 votes
2 answers
529 views

How to avoid running a batchable when an instance is already running?

We have several batchables that if run in parallel trample over each other's results. So I want to block a second invocation if there is already one running and just tell the user to wait. My first ...
Keith C's user avatar
  • 134k

1
2 3 4 5
7