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
5 votes
1 answer
3k views

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

I am pretty new to Apex and trying to learn as much as possible. Any help would be really appreciated. I have two classes. Invokeable Apex Class: This class is just getting called by a Process (...
Aditya Singh's user avatar
26 votes
5 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
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
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
2 votes
1 answer
3k views

Future Method: Too many future calls : 51

Working on a future method to post values to external web service. But since there is a limit of 50 callouts per invocation, I am getting error "Too many future calls : 51". Cases are loaded into ...
sf_user's user avatar
  • 2,238
6 votes
2 answers
12k views

Calling future method from batch class?

I got a situation where i need to invoke future method from batch class. And i know that it is not possible to do. But there might be some workarounds to achieve it, right? And i dont want to invoke ...
College Management's user avatar
8 votes
1 answer
14k 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
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,694
40 votes
3 answers
17k 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
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
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
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,071
10 votes
2 answers
11k 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,069
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
6 votes
1 answer
6k views

Queueable Job limit hit when trigger is batched

I am trying to run a very simple trigger, in concept. The purpose of the trigger is to count some items simply, then update a field on two objects based on that number. At first, I attempted to ...
Konnor McDowell's user avatar
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
5 votes
4 answers
11k views

Pass List<SObject> to @Future

I have the following list in a trigger. list<Employees__c> employeesToUpdate = new list<Employees__c>(); I want to pass the list to a Future method. All I really need is the ID of the ...
Matt M's user avatar
  • 1,477
4 votes
1 answer
4k views

Issue creating user and setting password

I am experiencing an issue creating users and setting their password. I have a need to setup a great deal of users but only activate them as they attempt to login. The creation process and activation ...
Chris's user avatar
  • 1,675
4 votes
1 answer
2k views

Saleforce Too many future calls: 11

I have a business logic as follows. 1. A web service class parses XML file containing case data and loads the case to SF. 2. Trigger that on update of case email field make a call to future method ...
Bharadwaj Urma's user avatar
2 votes
1 answer
3k views

Processing callouts from Batch

I have a tough scenario where a future method should be called from a batch.I came across various articles stating that it is not possible. My scenario is i need to send emails for contacts of account ...
Manoj Chandran's user avatar
2 votes
2 answers
2k views

Future Method Static

I am new to Salesforce and hence a lot of silly questions. What is the rational behind defining future methods as Static? I mean has these methods been not static what harm would have they caused?
Deep Singhal's user avatar
2 votes
1 answer
15k views

Is it possible to call Batch from a future call?

I was wondering if it is possible to call a batch from a @future method? The reason I am asking as you may have guessed is because I am trying to call batches from a trigger. Eg: Leads are inserted ...
Masoud Az's user avatar
2 votes
2 answers
3k views

REST API calls to 3rd Party (Pardot), multiple @future callouts

Setup: Pardot (3rd Party services I'm using) requires you to request an API_Key by submitting your email, password, and user_key so that you can then use the api_key with the user_key to do any API ...
Xtremefaith's user avatar
  • 4,540
1 vote
2 answers
2k views

Using future method in triggers [closed]

Trigger batch size can be 200. If i call future method(callout=true) on every batch object, this will throw limits error or not? If it throw, how can i avoid this?
Swan768's user avatar
  • 41
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,338
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
4k 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,338
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
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
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
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
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,815
7 votes
2 answers
15k 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
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
6 votes
1 answer
7k 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
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
1 answer
1k views

testing future with callout from schedulable class

I'm definitely missing something. How do I test Schedulable class with a future method that does a callout?I have 100% code coverage of the Schedulable class but 0% of my service.The test fails as no ...
user682217's user avatar
  • 1,171
6 votes
3 answers
19k 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.1k
5 votes
1 answer
1k views

Design Question: Any way around the "System.AsyncException: Future method cannot be called from a future or batch method" error in this situation?

Goal: Attempt to Authenticate then execute authenticated API request with minimal code in a componentized/modularized fashion. The Players: Helper_Outbound_API_Request: Standardized Flow which ...
zainogj's user avatar
  • 1,854
4 votes
2 answers
2k views

How to mock System.isFuture()?

I am writing some tests and I have encounter a problem. In my main app I have the following logic: public static void main() { if (System.isFuture()) { System.debug('Is future'); // ...
Matej J's user avatar
  • 143
4 votes
1 answer
2k views

Future Method to Trigger to Future Method

I was attempting to call a future callout method from a trigger and am getting the error that a future method can not be called from a future or batch method. The trigger is being called on insert of ...
mplax's user avatar
  • 373
3 votes
1 answer
4k views

@InvocableMethod/Process.PluginResult And @Future

Is it possible to set either the @InvocableMethod or Process.Plugin with a @future(callout=true)? My problem (bear with me): I have a trigger that calls a class the class creates an object and ...
Olivia's user avatar
  • 3,451
3 votes
1 answer
901 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,451
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
2k views

Can flow commit changes prior to invoking a method?

I'm trying to get some advanced architecture setup for my company, but I'm running into an issue with my design; looking for help. I'm attempting to execute an API call from Flow, but I'm getting the ...
zainogj's user avatar
  • 1,854
2 votes
2 answers
1k views

future method concurrency

I have a button that calls a very complex feature that caused salesforce limits to be reached. I modified the method in asynchronous (@future) and added two states: "waiting" and "not processed". ...
Pericle Parquet's user avatar
2 votes
2 answers
1k views

System.CalloutException: You have uncommitted work pending during Test for callout in @future method

SOLUTION An object has workflow rule that sends an email and it was not mocked EDIT I am simply trying to test future method that invokes SOAP service, but I get an exception. EDIT 2 I have @...
Vladyslav K's user avatar
  • 2,733
2 votes
1 answer
174 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
2 answers
4k views

How to get apex job id based on future call

Is it possible to get Apex Job Id in Apex job after executing the future call? Basically I want to get the job Id and its detail information to copy it to another custom object. So after the future ...
Rival's user avatar
  • 601