Skip to main content
New
Stack Overflow Jobs powered by Indeed: A job site that puts thousands of tech jobs at your fingertips (U.S. only). Search jobs
33 votes
Accepted

Queueable - Callout not allowed from this future method

You need to add Database.AllowsCallouts to your class, not @future(callout=true). The error is erroneous. public class getAccountUpdatesfromEndpoint implements queueable, Database.AllowsCallouts {
sfdcfox's user avatar
  • 494k
19 votes
Accepted

Does queueing a future method count as DML?

Using System.enqueueJob, Database.executeBatch, System.scheduleBatch, System.enqueueJob, and @future methods all modify the state of the database, so for purposes of callouts, count as a DML operation....
sfdcfox's user avatar
  • 494k
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, ...
sfdcfox's user avatar
  • 494k
16 votes
Accepted

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

First thing even though future methods are there for a while they are a thing of past. Going forward unless you have existing future code the suggestion is to move your code to Queueable apex. Think ...
Hemavantha Rajesh Varma Mudunu's user avatar
15 votes

Pass List<SObject> to @Future

According to the documentation here: Methods with the future annotation must be static methods, and can only return a void type. The specified parameters must be primitive data types, arrays of ...
Todd Sprinkel's user avatar
13 votes
Accepted

Help on Invokable Apex Test class and @Future callout Apex test Class

Basically, you need to know about how to test HTTP callouts, and how to test future methods. Once you've gotten that far, you'll see that the unit test would look like: @isTest class MakeCalloutTest ...
sfdcfox's user avatar
  • 494k
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<...
Pranay Jaiswal's user avatar
12 votes
Accepted

Is it possible to handle Trigger.oldMap in @future method?

You can user JSON.serialize() in your trigger to serialize the Old and New Maps and JSON.deserialize() in your @future annotated method to get the actual object and compare the old and new values. So,...
Mahmood's user avatar
  • 5,944
11 votes

Wait for Future Method execution before doing DML

SF will just not let you do a synchronous callout from a trigger. Which makes sense because the external system might be slow, and SF has to lock the record being updated while your trigger runs. If ...
Aidan's user avatar
  • 13.7k
11 votes
Accepted

Diference between @future (callout= true / false)

If you want to call third party system or any http call outside of salesforce system you need to set callout=true in the future method. If you set it to false it means the method is not making any ...
RedDevil's user avatar
  • 7,821
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 ...
Aidan's user avatar
  • 13.7k
10 votes
Accepted

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

The list of primitives doesn't include Map, Set, or List. Therefore, what you have is a collection of non-primitives. They've also explicitly excluded Object, so you can't weasel your way around that ...
sfdcfox's user avatar
  • 494k
10 votes
Accepted

Future Method and Static Variables

Static variables in Apex only retain their value through the course of a single transaction. Future methods by nature execute in a separate transaction, which means that your static variables are ...
David Reed's user avatar
  • 93.1k
10 votes
Accepted

First error: Too many query rows: 50001

While it won't fix your issue, never use the global access modifier unless you know you need it. Take advantage of the QueryLocator pattern and iterate over your query itself: Instead of: global ...
Adrian Larson's user avatar
  • 150k
9 votes
Accepted

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

The problem was -- I was executing anonymous code and checking the "Open Log" option. The call was actually generating two separate logs -- one for the anonymous code, and another for FutureHandler, ...
bertday's user avatar
  • 251
9 votes
Accepted

Future Method to Trigger to Future Method

If your code is already asynchronous, you don't need to use a @future method to call out. So you can add checks for this sort of thing. public static void makeCallout(/*params*/) { if (!system....
Adrian Larson's user avatar
  • 150k
9 votes
Accepted

Confused by CalloutException

Some operations are "DML-ish", meaning they persist something to the database to be committed at the end of the transaction, just not a standard DML operation on an sObject. Enqueuing Batch Apex, for ...
David Reed's user avatar
  • 93.1k
9 votes

Getting error System.AsyncException: Future method cannot be called from a future or batch method: when I am calling future method from a trigger

The error message does a pretty good job of describing the issue here. You have a trigger on Lead that calls an asynchronous @future method Your @future method updates your Leads Which causes your ...
Derek F's user avatar
  • 62.1k
8 votes

First error: [UNKNOWN_EXCEPTION] ConcurrentPerOrgLongTxn Limit exceeded

I've done some more research to this and created a repository containing code to reproduce: https://github.com/koenfaro90/SFDC-ConcurrentPerOrgLongTxn-Reproduction It seems that these days the ...
Koen Faro's user avatar
  • 773
8 votes

Diference between @future (callout= true / false)

The document you linked and the annotation itself both seem quite clear: To allow callouts in a future method, specify (callout=true). The default is (callout=false), which prevents a method from ...
Adrian Larson's user avatar
  • 150k
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 ...
Keith C's user avatar
  • 136k
8 votes
Accepted

How to do a dependent callout from a future callout

Instead of using @future, you should use Queueable Apex. Queueable Apex, lets you chain jobs. To allow callouts, you need to specify Database.AllowsCallouts public class AsyncExecutionExample ...
Daniel Hoechst's user avatar
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 ...
sfdcfox's user avatar
  • 494k
8 votes
Accepted

Using Apex, how do I monitor the daily @future limits?

As sfdcfox pointed out, this is a shared limit for all async operations in the org. You can monitor this directly in Apex via the OrgLimits class. Map<String,System.OrgLimit> limitsMap = ...
Daniel Ballinger's user avatar
7 votes

Pass List<SObject> to @Future

SFDC wants you to send ID's because it wants to re-query back out the data because an @future can fire anytime after it is called, the issue is that items in your List<Employees__> can change, ...
EricSSH's user avatar
  • 4,344
7 votes
Accepted

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

As the error states you are calling a future method from another future method . Your class A calls Class B but I see again you call Class A methods in Class B causing recursion . Hence would ...
Mohith Shrivastava's user avatar
7 votes

how to test a future method which makes callouts?

Here is where Test.startTest() and Test.stopTest() come in to play. Structure your test to do all the data setup, then call startTest(). Execute your tested method and then call StopTest(). Among ...
Kevin P's user avatar
  • 7,258
7 votes

Pass List<SObject> to @Future

+1 for passing the IDs. But for completeness, be aware that you can use a string to pass complex data, with JSON being the obvious format choice. So JSON.serialize, pass that string to the @future ...
Keith C's user avatar
  • 136k
7 votes

First error: [UNKNOWN_EXCEPTION] ConcurrentPerOrgLongTxn Limit exceeded

Well, Salesforce support confirmed ...There is no difference between the error message "ConcurrentPerOrgLongTxn Limit exceeded" and "REQUEST_LIMIT_EXCEEDED: ConcurrentPerOrgApex Limit".. Guess ...
Koen Faro's user avatar
  • 773
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 ...
Ashwani's user avatar
  • 22.6k

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