Skip to main content

Questions tagged [future]

A future method runs in the background, asynchronously. You can call a future method for executing long-running operations, such as callouts to external Web services or any operation you’d like to run in its own thread, on its own time.

Filter by
Sorted by
Tagged with
40 votes
3 answers
18k views

Is there any way of confirming that an @future method has been called/queued in a test class?

I have a Controller (FooController) which calls an @future method (bar()) belonging to another class (FooServices). Ideally in my test class for this Controller (FooControllerTest) I only want to ...
Alex Tennant's user avatar
  • 13.6k
27 votes
4 answers
27k 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
2 answers
10k views

How can I determine how many future calls have been executed in 24 hours?

I just ran into a huge gotcha in Salesforce: the 24 hr limit on # of future calls - cf. http://www.sundoginteractive.com/index.php?/sunblog/posts/governor-limit-gotchas-part-1-the-future-call/. I ...
Evan Donovan's user avatar
26 votes
6 answers
38k views

Calling future method from Batch

I have a requirement where a future method need to be called from batch apex ,I came across various articles stating that a future method could not be called from the batch. Is there any alternate ...
Manoj Chandran'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
21 votes
2 answers
1k views

@Future at risk for race conditions?

Question If I invoke an @future method from a trigger that is performing a calculation based on data that is being committed in the trigger am I at a risk for a race condition? Background We're ...
Ralph Callaway's user avatar
18 votes
1 answer
12k views

Difference between Queueable apex and future method

I understand that you could pass collection of Sobjects to Queueable apex classes but not to future methods where we're restricted to only primitive collections. The reason it's not done for future ...
JJSHHS's user avatar
  • 505
18 votes
4 answers
6k views

Knowing if a future call is allowed

I'm having an issue where we have some code that can be called anywhere and then it makes an @future call to log a message to an external system. The problem is if this method is called (either ...
Patrick Connelly's user avatar
17 votes
3 answers
19k views

Future Method calling Another Future Method

I have two future methods f1 & f2. Each of them takes long time to process as such I have annotated them as @future. There is a scenario in which I need to make a callout to f2 from f1. Any ...
Iamauselessrightbrainer's user avatar
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,348
13 votes
2 answers
2k views

Does queueing a future method count as DML?

We need to implement the following pattern at my org: callout to external data source if that callout takes too long (according to some configurable threshold), log an error (ie do some DML) if that ...
Jim Madrigal's user avatar
13 votes
3 answers
2k views

Use JSON serialization to get around parameter limitations for future methods?

Future methods can only take primitives or collections of primitives as parameters. To get around this you could serialize Sobjects (or classes) to a string and then deserialize them in the future ...
Greg Grinberg's user avatar
12 votes
4 answers
8k views

How far in the future are @future annotated methods executed?

What is the maximum estimated time before execution of an @future annotated method starts, after the call to the function is made? Is this in the order of seconds? Or can it take up to minutes before ...
user254875486's user avatar
12 votes
4 answers
5k views

How can you avoid hitting 24-hour limits on emails and future calls?

I realize there are plenty of ways to try to avoid hitting limits in the first place, but when it comes to features with 24 hour limit plans, how can you know if you're getting close to them? And ...
Adam's user avatar
  • 4,348
11 votes
2 answers
9k views

How to work around the 100 callout limitation?

We need to have the ability to make more than 2999 callouts to a REST service. Currently, we are getting a raised exception when the number of callouts is more than current limit for callouts. Thus, ...
cloudy-ritz's user avatar
  • 2,583
11 votes
3 answers
3k views

Avoiding use of future calls in triggers?

I have some code I'd like to change in a trigger. The issue is that there is a field that is being updated with a prefix plus the value of a field in the object that is an automatic number. The ...
Robert Harper's user avatar
11 votes
1 answer
12k views

Is it possible to make Remote Action Asynchronous?

I have a Remote action call from my Visualforce Page. Visualforce.remoting.Manager.invokeAction( '{!$RemoteAction.PartnerPrimeSubController.calculatePartnerPrimeSub}', ...
Jag's user avatar
  • 1,205
11 votes
3 answers
4k views

Why is Map<Id, Set<Id>> an unsupported parameter type in future methods?

I am trying to create some junction records via callout (in this case, SkillUser records). Since I am doing so from a trigger, I need to use a @future annotated method. The Apex Developer Guide states ...
Adrian Larson's user avatar
  • 150k
11 votes
1 answer
5k views

Chaining Scheduled Apex to process callouts every 30 seconds

We wanted to create an outbound message queue system that would process requests individually and in order to any external web service. The frequency that these requests should be processed is ...
mdh350's user avatar
  • 113
10 votes
2 answers
12k views

Queueable - Callout not allowed from this future method

I am using a queueable class to handle various date ranges that are then sent to a web service. Upon calling the queueable class I am receiving the following error: Callout not allowed from this ...
S.B.'s user avatar
  • 2,091
10 votes
3 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,081
10 votes
2 answers
10k views

First error: [UNKNOWN_EXCEPTION] ConcurrentPerOrgLongTxn Limit exceeded

We are currently facing a Salesforce platform error I have never seen before; First error: [UNKNOWN_EXCEPTION] ConcurrentPerOrgLongTxn Limit exceeded This happens both when logging into the API ...
Koen Faro's user avatar
  • 773
10 votes
4 answers
4k views

Chaining @future methods

Is there any way/workaround at all to call a future method immediately from another future event? If not what's the fastest way to call my future method indirectly? I basically have a 3rd party ...
Rowan's user avatar
  • 313
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
3k views

GetContentAsPDF from Batch Apex and Trigger fails with new Update

[Salesforce Update] The critical update named “PageReference getContent() and getContentAsPDF() Methods Treated as Callouts” was scheduled for auto-activation in Winter ’16. To allow for planning ...
RajeshShah's user avatar
  • 1,754
9 votes
2 answers
19k 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,882
9 votes
3 answers
11k views

how to test a future method which makes callouts?

I am practising the Integration workbook provided by salesforce. In tutorial#2 there's a class which makes future callouts to a Heroku app.This class is called by an after update trigger. Callout ...
Jarvis's user avatar
  • 2,110
9 votes
1 answer
10k views

Future method cannot be called from a future or batch method, Case Trigger with Salesforce for Social

I get the following inside a Case Trigger when I try to call a future method: System.AsyncException: Future method cannot be called from a future or batch method So far this exception ONLY occurs ...
Tom's user avatar
  • 133
8 votes
2 answers
7k views

What is the best approach to call a webservice from SFDC?

Objective: When an Account is created in Salesforce I need to call a SAP webservice and create a customer in SAP. What would be best approach? To call the SAP webservice from the Account trigger ...
Bforce's user avatar
  • 6,828
8 votes
1 answer
15k views

Error: Future method cannot be called from a future or batch method

I have a managed packaged that I recently updated and it threw an error for a future method I have that sends information to a third party. The error I received was: Future method cannot be called ...
J.koh's user avatar
  • 189
8 votes
1 answer
2k views

Future vs batch

I need to make asynch call from trigger. Records are comming (1 or 1000 at once) each minute and I need to process them from trigger asynchronously. As I see limits for future and batch jobs are the ...
Natallia's user avatar
  • 3,231
8 votes
2 answers
20k views

Call Queueable from future method

I have a use-case where I need to execute some logic in async mode and I found that using Queueable Interface I can achieve that. But when I am trying to the use the Queuable Interface, some issues ...
S.Sharma's user avatar
  • 1,637
8 votes
4 answers
4k 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
8 votes
1 answer
2k views

Test execution order issues with Queueable and @future method

Test code: * Test.startTest(); * System.enqueueJob(new MyJob()); * Test.stopTest(); * System.debug('Quering record for assertion'); Expected Queueable job execution: * Job Start * Query records * ...
Vladyslav K's user avatar
  • 2,743
8 votes
1 answer
1k views

Calling a Callout via @future still gives uncommitted work pending error

Class A is simple page controller. It creates an instance of Class B. The user can click a button on a VF page to invoke a pagereference method in Class A that will invoke various methods in class B, ...
BritishBoyinDC's user avatar
8 votes
2 answers
508 views

Callout from a future event

I have a managed app that does a callout (REST API POST) on Account save. The managed app is developed by a 3rd party that we have no control of. The callout creates a future event which gets an id ...
Rowan's user avatar
  • 313
7 votes
2 answers
14k views

Error: Future method cannot be called from a future or batch class [closed]

My requirement is getting latitude longitude from google map for that i wrote trigger and used @future callouts. now i need to run batch class to update contact records but contacts not updating ...
user123's user avatar
  • 271
7 votes
2 answers
16k views

Debug or view status of a @future method

Can I see the errors or debug messages my @future calls may be generating? How can I see if a @future method was executed at all? Details: I have a trigger which needs to update some User accounts in ...
Mehdi Maujood's user avatar
7 votes
2 answers
9k views

Getting current PageReference from Controller Extension in @future context

I'm attempting to get current pageReference for a VisualForce page (renderAs=pdf) that is being executed in @future context, but at the moment it is just returning a null. So I assume the problem is ...
Mattisdada's user avatar
  • 1,081
7 votes
2 answers
2k views

Cannot deserialize JSON as abstract type?

While writing a class to help me manage @future jobs for a project, I stumbled onto an error message I can find very little help on. Cannot deserialize JSON as abstract type I used an interface ...
battery.cord's user avatar
  • 8,835
7 votes
1 answer
462 views

Is an AsyncApexJob record inserted immediately at the end of a transaction?

Is an AsyncApexJob record inserted immediately at the end of a transaction or is it possible that there is a delay between those two events? I couldn't find firm guarantee in the documentation on that....
ipavlic's user avatar
  • 3,736
7 votes
3 answers
3k views

Can future execution start before the synchronous execution is completed

Is there a way for @future annotated method to start execution before the synchronous request which invokes it has completed. In other words, do I have some guarantees that the timing will look like ...
ipavlic's user avatar
  • 3,736
7 votes
1 answer
1k views

@future and triggers

I want to do a bulk update of records in parallel, but Batch Apex doesn't permit this. I was wondering if the following solution would work: I have an SObject defined that holds a value for the ...
user10015's user avatar
6 votes
3 answers
11k views

Diference between @future (callout= true / false)

I don't understand the difference between: @future (callout= true) and @future (callout= false) I have read the documentation, but I don't understand where to use one or the other.
David Marciel's user avatar
6 votes
3 answers
20k views

Prevent trigger from running in single test

Ok so I have a fairly complex scenario I need to test... I have a Trigger on a MyObject__c that creates PermissionSetAssigments when MyObject__c is inserted. Because PS Assignments are system ...
NSjonas's user avatar
  • 10.2k
6 votes
2 answers
1k 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
1 answer
8k views

Wait for Future Method execution before doing DML

Scenario : Before inserting a record I will check another System(REST call) and then decide(control) to insert or update in Trigger context. I have Trigger which does REST call inside future method. ...
Soberano's user avatar
  • 1,232
6 votes
2 answers
11k views

You have uncommitted work pending. Please commit or rollback before calling out

i have written a future method here is source code @future(callout=true) public static void futureDownloadAttachment(Set<ID> documentsID){ List<SpringCM_Attachment__c> logs = [...
mathlearner's user avatar
  • 2,151
6 votes
1 answer
2k views

Why do debug logs not always work for a @future method?

I'm working on an Apex class that contains a method annotated with @future. Inside of the method I have a few system.debug statements I'm using to figure out why it's not working. The problem is -- if ...
bertday's user avatar
  • 251
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

1
2 3 4 5
10