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
15 votes
1 answer
9k 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 ...
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
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
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
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
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,752
11 votes
3 answers
43k 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
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
5 votes
2 answers
785 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.8k
4 votes
1 answer
3k views

Does Test.stopTest() cause ALL waiting asynchronous functions to fire?

For practice, I'm composing on a unit test for a Schedulable class: /** * Example of scheduling Apex Batch Processing * @see Apex Workbook, page 68 **/ global class WARE_CleanMerchandiseScheduler ...
Brian Kessler's user avatar
0 votes
1 answer
863 views

Want to create Record in batch class and there is no record to query in start method

I had one batch class in which i am passing some data required for creating object record.But when i call that batch class from parent class variables are initialized but start method are not called ...
Paresh Patil's user avatar
0 votes
3 answers
1k views

Can Queueable run in parallel with calling transaction?

SimpleQueueable.cls: public with sharing class SimpleQueueable implements System.Queueable{ public void execute(System.QueueableContext ctxt){ //query the record inserted in calling ...
javanoob's user avatar
  • 8,787
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
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,328
10 votes
0 answers
806 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
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
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
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
6 votes
2 answers
626 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
  • 135k
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
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
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
1 answer
352 views

Best approach to make callouts from trigger

I have a requirement in which, for each time an account is inserted, I have to make a callout to an external system sending some data of the record and then the API returns a unique Id that I have to ...
joacoiudica's user avatar
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
545 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
4 votes
2 answers
4k views

What's the difference between AsyncApexJob and CronTrigger?

Roughly I know that when I schedule a Schedulable, I'm creating both a CronTrigger and an AsyncApexJob, but I'm confused as to how the two objects relate to each other and what the significance of ...
user823447'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
1 answer
1k views

Batch execute is slow because of huge unused gaps in DevConsole timeline

I have a long running batch that is taking days to execute and creates millions of records. To speed it up I used the profiling tools of the Developer Console. Per batch execute() I see this timeline ...
Robert Sösemann's user avatar
4 votes
1 answer
288 views

Does Apex Engine maintains old version of apex code for Async Apex?

Suppose I have a batch running that is processing millions of records(that would take hours), then I deploy a code during execution that changes the batch logic, will remaining record get processed ...
Pranay Jaiswal's user avatar
3 votes
2 answers
5k views

Asynchronous getContent hit org.apache.commons.httpclient.RedirectException: Maximum redirects (100) exceeded

we're having an issue with getContent() in asynchronous context, and I just can't find any way to work around it... We're exposing invocable Apex in our managed package, and one of them allow our ...
Cissou's user avatar
  • 83
3 votes
2 answers
903 views

Unable to do callout from PostInstall Script

As per the Salesforce documentation, Post-Install script can perform callouts using an async operation only. https://help.salesforce.com/articleView?id=apex_post_install_script.htm&type=5 So, I ...
Hemant Keni's user avatar
3 votes
1 answer
884 views

Custom Logging and Future Methods

I have been reading up on the custom logging, DML, and exceptions but haven't seen anything that talks about @Future methods and exceptions. I have two scenarios: A Button is clicked on a Lead, ...
Olivia's user avatar
  • 3,431
3 votes
1 answer
2k views

Testing multiple asynchronous processes

I have a test that for it's data setup I need to fire multiple asynchronous processes. I have a suspicion, that they do not finish sequentially one after another. I think Test.startTest()/Test....
dzh's user avatar
  • 4,016
3 votes
1 answer
330 views

How to monitor not yet started jobs of a Queuable chain

I am wrapping my head around how to use Apex Queuable as a queue and not as a chain. As I understand all the code samples out there, the next job is enqueued after the work of the previous one is done....
Robert Sösemann's user avatar
2 votes
2 answers
4k views

How to synchronize asynchronous Apex

There are different ways to offload long-running processes to asynchronous apex: we got future calls, scheduled Apex, batch Apex and, more recently, Queueable Apex. They are all good to launch "fire ...
mkorman's user avatar
  • 4,026
2 votes
2 answers
859 views

Queueable being called from a trigger by an Asynchronous Process

Recently we moved our logic in our trigger to be asynchronous and now the helper method that the triggers call looks something like this (specifics obfuscated since it's company code): global static ...
J. Larson's user avatar
2 votes
1 answer
436 views

LWC enforce and validate an API method before calling another method

I'm looking to enforce a validation of sort to be implemented in LWC that consumes an external API. The validation call is suppose to check user access (an APEX based external API validation). Then ...
VarunC's user avatar
  • 5,900
2 votes
1 answer
816 views

How to know when the last batch job in parallel execution finishes?

I have an apex class that is executed in parallel by calling Database.executeBatch() in a loop, where each instance processes a chunk of a dataset. After all the jobs that were executed finish I need ...
TemporaryFix's user avatar
  • 2,887
2 votes
1 answer
690 views

How can I make multiple Http callouts in a row?

I need to build an apex class that will perform multiple callouts in a row to an external system and upsert some records. Right now I'm sending a POST method with a query in the body and getting an ...
Leonardo dos Santos Zamboni's user avatar
2 votes
1 answer
172 views

Heuristics to decide if to run an operation sychronous or asynchronous

Im our app we recently had to switch many operations from short running synchronous calls to asychronous Batch or future calls. It helps us overcome the many limits but also introduces many other ...
Robert Sösemann's user avatar
2 votes
0 answers
2k views

How to Launch Asynchronous Record Triggered Flow each time a Date Field is updated

I have a date field. I want to update the record every time this field is updated. Inside of the Record Triggered Flow I have an ISCHANGED condition and am seeing the following error when I try to ...
Matthew Metros's user avatar
1 vote
1 answer
1k views

Best way to add a progress bar to indicate loading?

I've got a complex process that takes about thirty seconds to execute, depending on how many records are in the org. I can estimate the completion percentage by iterating a count variable in my for ...
Isaac L's user avatar
  • 174
1 vote
1 answer
2k views

What is the life-cycle of static properties in Apex classes?

Sometimes when developing Apex, I've populated some static property. But then later -- most often in an Async or Test context -- I go to access it again and discover SFDC is behaving like it is ...
Brian Kessler's user avatar
1 vote
3 answers
2k views

Future method in trigger causes batch failures

I've recently been asked to convert a method in our account trigger to a future method to help reduce CPU errors during execution. When attempting to run all test classes in my org (for a completely ...
gNerb's user avatar
  • 9,441
0 votes
2 answers
2k views

Making Callout from Apex triggers [duplicate]

I have a Apex Trigger which makes the callout to the External system when a field in a record is updated. The Apex Trigger and the Callout method are like below trigger updateLocation Account (after ...
user81642's user avatar
  • 667
0 votes
1 answer
438 views

Choose async or sync based on amount of data returned or trigger size?

Can anybody guide me through any framework which I can refer in order to achieve this use case?I am not able to get my head around it on how to do it efficiently. I want to process records in near ...
Isha's user avatar
  • 163
0 votes
2 answers
231 views

Service console waits for aura component to finish init before rendering case

I have an aura component (as managed package) in service console. the component fetches case's fields (via soql), sends them to an external server, gets a response, and displays it. everything works ...
Jonathan P's user avatar
0 votes
0 answers
737 views

Time-based Workflow Schedule Date keeps getting pushed forward 5 minutes

I created a record triggered after update flow that tests if a field has changed in the entry criteria, allowing me to create an async path: When a record is updated, the immediate path executes, ...
Swisher Sweet's user avatar
0 votes
1 answer
213 views

Deleting Scheduled Job versus Aborting job?

What will happen if the scheduled job is deleted and what happen if it is aborted. Do we have any significant difference
Vineel's user avatar
  • 65